通过dataset在student表里增加一个学生记录,运行后结果显示增加了,可是sqlserver中student表里没有增加,还是原来的数据,怎么改这个程序
程序代码如下:
<%@page language= "C# " %>
<%@import namespace= "System.Data "%>
<%@import namespace= "System.Data.SqlClient "%>
<%@import namespace= "System.Data.OleDb "%>
<html>
<script language= "C# " runat=server>
void page_load(object serder,EventArgs e)
{
SqlConnection sqlcon=new SqlConnection ( "Data Source=JSJ;uid=sa;pwd=;Initial Catalog=chapter ");
DataSet ds=new DataSet ();
sqlcon.Open ();
SqlDataAdapter sqld=new SqlDataAdapter ( "select * from student ",sqlcon);
SqlCommandBuilder objcmdbld=new SqlCommandBuilder (sqld);
sqld.Fill (ds, "tabstudent ");
DataRow drow;
drow=ds.Tables [ "tabstudent "].NewRow ();
drow[0]= "97070708 ";
drow[1]= "huang ";
drow[2]=30;
drow[3]= "beijing ";
ds.Tables [ "tabstudent "].Rows .Add (drow);
ds.Tables[ "tabstudent "].AcceptChanges ();
sqld.Update (ds, "tabstudent ");
dg.DataSource=ds.Tables [ "tabstudent "].DefaultView ;
dg.DataBind();
sqlcon.Close ();
sqlcon=null;
labcontent.Text+= "增加成功 ";
}
</script>
<body>
<form runat=server>
<asp:datagrid id=dg runat=server/> </br>
<asp:label id=labcontext runat=server /> <br/>
</form>
</body>
</html>
已经在sql2000中建了一个名为chapter的数据库,里面有表student内容如下:
studentid name age address
97070701 kang 24 tianjin
97070702 li 21 shanghai
97070703 wang 20 beijing &n