当前位置:编程学习 > C#/ASP.NET >>

求助!

 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
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,