日期:2014-05-19  浏览次数:20422 次

asp.net数据库的连接问题
窗体上只有一个DataGrid和SqlConnection控件,所添加代码如下
       private   void   Page_Load(object   sender,   System.EventArgs   e)
{
BindDataGrid();
}
       private   void   BindDataGrid()
{
sqlConnection1.Open();
SqlCommand   sqlCommand   =   new   SqlCommand();
sqlCommand.CommandText   =   "select   FirstName,LastName, "+
"Title,Extension   from   Employees ";
sqlCommand.Connection   =   sqlConnection1;
SqlDataReader   sqlDataReader   =   sqlCommand.ExecuteReader();
DataGrid1.DataSource   =   sqlDataReader;
DataGrid1.DataBind();
sqlConnection1.Close();
}
运行后显示服务器连接不上:sqlConnection1.Open();行有错

------解决方案--------------------
sqlConnection sqlConnection1=new sqlConnection( "server=.;database=news;uid=sa;pwd=; ");
sqlConnection1.Open();