DataGrid
小弟学习DataGrid 用DataGrid 显示数据报错误...不解.请那位大虾帮一下忙再线等bjSqlConnection = new SqlConnection("Server = Fiona;Database = Fiona; integrated security=SSPI");
objSqlDataAdapter = new SqlDataAdapter("select * from stu",objSqlConnection);
objSqlDataAdapter.Fill(objDataSet,"stu");
dataGrid1.DataSource = objDataSet.Tables[0].DefaultView;
主要是第3行报错... --------------------编程问答-------------------- 那位来看看看袄 帮帮忙 --------------------编程问答-------------------- Mark!友情UP --------------------编程问答-------------------- SqlConnection sqlConn = new SqlConnection();
sqlConn.ConnectionString = "Server = Fiona;Database = Fiona; integrated security=SSPI";
SqlCommand sqlCmd = new SqlCommand();
sqlCmd.Connection = sqlConn;
sqlCmd.CommandText = @"select * from stu";
SqlDataAdapter sqlApt = new SqlDataAdapter();
sqlApt.SelectCommand = sqlCmd;
DataSet ds = new DataSet();
sqlApt.Fill(ds);
--------------------编程问答-------------------- objDataSet 实例化了没?
--------------------编程问答-------------------- 给你一个函数吧,返回记录集的,
public static DataSet dataToGridView(string strSql)
{
/// <summary>
/// 读取数据库表
/// </summary>
/// <param name="Path">文件名称</param>
/// <returns>返回一个数据集</returns>
OleDbConnection conn = new OleDbConnection();
conn.ConnectionString = connStrto;
conn.Open();
OleDbDataAdapter myCommand = null;
DataSet ds = null;
myCommand = new OleDbDataAdapter(strSql, connStrto);
ds = new DataSet();
myCommand.Fill(ds);
conn.Close();
return ds;
}
补充:.NET技术 , C#