做最好的自己~~

Be My Personal Best!

导航

SqlCommandBuilder 小示例

  protected void Button5_Click(object sender, EventArgs e)
    {

        SqlConnection conn = new SqlConnection("Server=.;Database=test;Integrated Security=SSPI");
        conn.Open();

        //填充DateSet
        SqlDataAdapter da = new SqlDataAdapter("select * from Test",conn );
        SqlCommandBuilder cb = new SqlCommandBuilder(da);
        DataSet ds = new DataSet();
        da.Fill(ds, "Test");
        //在使用Dateset之前我们必须ds.fill来填充内存数据库...

         //添加数据...
        DataRow dr = ds.Tables["Test"].NewRow();
        dr["StuId"]="444";
        dr["StuName"] = "中国";
        dr["Sutscore"] = 444;
        ds.Tables["Test"].Rows.Add(dr);

        try
        {
            da.Update(ds, "Test");
            Response.Write("数据已经添加");
        }

        catch
        {
            Response.Write("出现异常 ");
        }

        conn.Close();
    }

posted on 2008-06-11 21:55  阿万  阅读(741)  评论(3编辑  收藏  举报