2 u010341066 u010341066 于 2014.05.21 19:11 提问

总是报ExecuteReader: Connection 属性尚未初始化。属性尚未初始化。”是怎么回事啊

using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
//引入命名空间
using System.Data.SqlClient;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("Data Source=WIN-T440SQTMDUO;Initial Catalog=database;User ID=sa;Password=123456789");
con.Open();
if (con.State == System.Data.ConnectionState.Open)
{
Response.Write("SQL Server数据库连接开启!

");
}
    SqlCommand cx =new SqlCommand("con");//创建并初始化sqlcommand对象
    cx.CommandText = "select password from database where id=1";//所需要执行的sql语句
    SqlDataReader mm = cx.ExecuteReader();//执行查询
    Response.Write(mm);

}

}

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!