求助!
public partial class Form1 : Form{
SqlConnection cn = new SqlConnection("Data Source=.;Initial Catalog=Student;Integrated Security=True");
SqlCommand command;
SqlDataAdapter adapter;
DataSet ds = new DataSet();
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e) //查询
{
string sql = "select*from studentinfo";
command = new SqlCommand(sql,cn);
adapter = new SqlDataAdapter(command);
if (ds.Tables["stu"] != null)
{
ds.Tables["stu"].Clear();
}
adapter.Fill(ds, "stu");
dataGridView1.DataSource = ds.Tables["stu"];
}
private void button2_Click(object sender, EventArgs e) //修改
{
SqlCommandBuilder bulider = new SqlCommandBuilder(adapter);
adapter.Update(ds,"stu"); //此处编译不通过
}
} --------------------编程问答-------------------- 什么错误提示 --------------------编程问答-------------------- 提示sqlselectcoomend不能自动生成sql语句 --------------------编程问答-------------------- string sql = "select*from studentinfo";
楼主,你这里要不要空格下-->
string sql = "select * from studentinfo";
--------------------编程问答-------------------- 应该不是这原因吧 --------------------编程问答-------------------- 你adapter没有sql语句啊。 --------------------编程问答-------------------- 主键问题,你update没设置主键,就会报异常。
DataTable myDt=.Tables["stu"];
myDt.PrimaryKey=new DataColumn[]{myDt.Columns["id"]};
补充:.NET技术 , .NET Framework