DataSet插入數據

DataSet插入數據

SqlDataAdaptersda=new SqlDataAdapter(a,con);

sda.Fill(ds,"users");

  SqlCommandBuilderscb=  new SqlCommandBuilder(sda);

  DataRowdr=ds.Tables["users"].NewRow();

  dr["name"]="aa";

  dr["pass"]="aa";

  ds.Tables["users"].Rows.Add(dr);

  sda.Update(ds,"users");

Dataset在數據改變時候並不會產生sql語句,所以要使用SqlCommandBuilder ,當單個表的數據改變時自動產生sql語句

<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<FONT face="宋體">
<asp:Button id="Button1" style="Z-INDEX: 101; LEFT: 256px; POSITION: absolute; TOP: 96px" runat="server"
Text="Button" Width="104px" Height="40px"></asp:Button></FONT>
</form>
<%
 while(dr.Read())
 {
%>
<%=dr["name"]%>
<%=dr["pass"]%>
<br>
<%
 }
%>
</body>

nds.Tables["users"].Rows[1].Delete();
nsda.Update(ds,"users");





發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章