|
sp; sqlAdatper.Update(table); con.Close(); this.DataGrid1.EditItemIndex=-1; this.BindGrid(); } /// <summary> /// 点击删除时触发该事件 /// </summary> /// <param name="source"></param> /// <param name="e"></param> private void DataGrid1_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e) { SqlConnection con=new SqlConnection("server=accp-lzh;uid=sa;pwd=sasa;database=pubs"); SqlCommand selectCmd=con.CreateCommand(); selectCmd.CommandText="select * from publishers where pub_id like ''''99%''''"; SqlCommand deleteCmd=con.CreateCommand(); deleteCmd.CommandText="delete from publishers where pub_id=@pub_id"; SqlParameter PubIdPar=new SqlParameter("@pub_id",SqlDbType.Char,4,"pub_id"); PubIdPar.SourceVersion=DataRowVersion.Original; deleteCmd.Parameters.Add(PubIdPar); SqlDataAdapter sqlAdapter=new SqlDataAdapter(); sqlAdapter.SelectCommand=selectCmd; sqlAdapter.DeleteCommand=deleteCmd; DataSet ds=new DataSet(); con.Open(); sqlAdapter.Fill(ds,"publishers"); DataTable table=new DataTable(); table=ds.Tables["publishers"]; table.PrimaryKey=new DataColumn[]//定义主键,便于查找 { table.Columns["pub_id"] }; DataRow row=table.Rows.Find(e.Item.Cells[2].Text); row.Delete(); sqlAdapter.Update(table); con.Close(); this.DataGrid1.EditItemIndex=-1; this.BindGrid(); } private void DataGrid1_Disposed(object sender, System.EventArgs e) { } 上一页 [1] [2] [3] [4] [5] [6] [7] [8] 下一页 [C语言系列]NET 中C#的switch语句的语法 [系统软件]托拽Explore中的文件到VB.net的窗口 [系统软件]Boost库在XP+Visual C++.net中的安装 [常用软件]新配色面板:Paint.Net3.0RC1官方下载 [常用软件]用内建的“Net Meeting”聊天 [VB.NET程序]Henry的VB.NET之旅(三)—共享成员 [VB.NET程序]Henry的VB.NET之旅(二)—构造与析构 [VB.NET程序]Henry的VB.NET之旅(一)—失踪的窗体 [VB.NET程序]在托盘上显示Balloon Tooltip(VB.NET) [VB.NET程序]VB.NET中关于DataGrid颜色的自定义。
|