C#连接数据集问题
publicvoidfilltable(){DBHelperdb=newDBHelper();try{StringBuildersql=newStringBuilder(...
public void filltable()
{
DBHelper db = new DBHelper();
try
{
StringBuilder sql = new StringBuilder("select [id],");
sql.AppendLine("[nickname],[sex],[email],[phone],[address],[year]");
sql.AppendLine("from [学生信息]");
sql.Append("order by [id]");
adaptergrade = new SqlDataAdapter();
SqlCommand comm = new SqlCommand(sql.ToString(), db.Connection);
adaptergrade.SelectCommand = comm;
if (ds.Tables["[学生信息]"] != null)
{
ds.Tables["[学生信息]"].Clear();
}
adaptergrade.Fill(ds, "[学生信息]");
this.dataGridView1.DataSource = ds.Tables["[学生信息]"];
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, caption, MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
adaptergrade.SelectCommand = comm;这一句写和没写一样,都提示未将对象引用到实例 展开
{
DBHelper db = new DBHelper();
try
{
StringBuilder sql = new StringBuilder("select [id],");
sql.AppendLine("[nickname],[sex],[email],[phone],[address],[year]");
sql.AppendLine("from [学生信息]");
sql.Append("order by [id]");
adaptergrade = new SqlDataAdapter();
SqlCommand comm = new SqlCommand(sql.ToString(), db.Connection);
adaptergrade.SelectCommand = comm;
if (ds.Tables["[学生信息]"] != null)
{
ds.Tables["[学生信息]"].Clear();
}
adaptergrade.Fill(ds, "[学生信息]");
this.dataGridView1.DataSource = ds.Tables["[学生信息]"];
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, caption, MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
adaptergrade.SelectCommand = comm;这一句写和没写一样,都提示未将对象引用到实例 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询