怎么不能够在DataGrid里面显示数据库信息?连接错了?
我是在信息DataGrid的使用啊,是抄的书上的语句,怎么就是不行的。数据库是微软的那个Pubs数据库啊!!
++++++++++++++++++++++
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DataGrid DataGrid1;
private void Page_Load(object sender, System.EventArgs e)
{
LoadData();
}
private void LoadData()
{
string connStr = @ "Data Source = writer\example;Integrated Security=SSPI;Initial Catalog=pubs ";//我想可能是连接语句错了啊!!怎么会不行的啊,我明明是抄的书上的啊!!
string queryStr = "SELECT emp_id,fname,lname FROM employee ";
SqlConnection myConnection = new SqlConnection(connStr);
SqlDataAdapter myDataAdapter = new SqlDataAdapter(queryStr,myConnection);
myConnection.Open();
DataSet myDs = new DataSet();
myDataAdapter.Fill(myDs, "employee ");
this.DataGrid1.DataSource = myDs;
DataGrid1.DataBind();}
private void DataGrid1_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
this.DataGrid1.CurrentPageIndex = e.NewPageIndex;
this.DataGrid1.DataBind();
}
++++++++++++++++++++++++++++++++++++++++++
错误提示为:
SQL Server 不存在或访问被拒绝。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息:
System.Data.SqlClient.SqlException: SQL Server 不存在或访问被拒绝。
源错误:
行 55: SqlDataAdapter myDataAdapter = new SqlDataAdapter(queryStr,myConnection);
行 56:
行 57: myConnection.Open();
行 58: DataSet myDs = new DataSet();
行 59: myDataAdapter
------解决方案--------------------试一下语句:string connStr = "uid=sa;pwd=;initial catalog=pubs ";