| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 799 人关注过本帖
标题:求助,SQL2005连接问题
只看楼主 加入收藏
zore0
Rank: 1
等 级:新手上路
帖 子:33
专家分:0
注 册:2008-9-8
收藏
 问题点数:0 回复次数:1 
求助,SQL2005连接问题
using System;
using
using System.Data;
using System.Configuration;
using System.Drawing;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

public partial class _select : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection("server=.; database=select;uid=sa;pwd=;");
        con.Open;
        SqlCommand cmd = new SqlCommand("select * from provence", con);
        SqlDataReader sdr = cmd.ExecuteReader();
        this.ddlPro.DataSource = sdr;
        this.ddlPro.DataTextField = "ProName";
        this.ddlPro.DataValueField = "ProID";
        this.ddlPro.DataBind();
        sdr.Close();
      
    //city的绑定
        SqlCommand citycmd = new SqlCommand("select * from City where ProID=" + this.ddlPro.SelectedValue, con);
        SqlDataReader sdrcity = citycmd.ExecuteReader();
        this.ddlCity.DataSource = sdrcity;
        this.ddlCity.DataTextField = "CityName";
        this.ddlCity.DataValueField = "CityID";
        this.ddlCity.DataBind();
        sdrcity.Close();
        con.Close();

    }
}


在con.Open;出现 CS0201: 只有 assignment、call、increment、decrement 和 new 对象表达式可用作语句
这是怎么回事?怎样才能解决?
搜索更多相关主题的帖子: sql 连接 
2008-10-02 14:43
bygg
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:乖乖的心中
等 级:版主
威 望:241
帖 子:13555
专家分:3076
注 册:2006-10-23
收藏
得分:0 
建议将SqlConnection con = new SqlConnection("server=.; database=select;uid=sa;pwd=;");
        con.Open;
        SqlCommand cmd = new SqlCommand("select * from provence", con);
        SqlDataReader sdr = cmd.ExecuteReader();
        this.ddlPro.DataSource = sdr;
        this.ddlPro.DataTextField = "ProName";
        this.ddlPro.DataValueField = "ProID";
        this.ddlPro.DataBind();
        sdr.Close();
SqlConnection con = new SqlConnection("server=.; database=select;uid=sa;pwd=;");
        con.Open;
        SqlCommand cmd = new SqlCommand("select * from provence", con);
        SqlDataReader sdr = cmd.ExecuteReader();
        this.ddlPro.DataSource = sdr;
        this.ddlPro.DataTextField = "ProName";
        this.ddlPro.DataValueField = "ProID";
        this.ddlPro.DataBind();
        sdr.Close();
写在一个共用方法中,每次调用就行了.
不要在一个SqlConnection中执行多个命令.

飘过~~
2008-10-04 12:11
快速回复:求助,SQL2005连接问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.019601 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved