sql - asp.net sql删除datatable生成的一行
问题描述
我想创建一个删除按钮,获取旁边的 id
我获取数据的方法是这样的一个按钮生成创建图片
protected void btnSelect_Click(object sender, EventArgs e)
{
try /* Select After Validations*/
{
using (NpgsqlConnection connection = new NpgsqlConnection())
{
connection.ConnectionString = ConfigurationManager.ConnectionStrings["SHOT"].ToString();
connection.Open();
NpgsqlCommand cmd = new NpgsqlCommand();
cmd.Connection = connection;
cmd.CommandText = "Select * from shot_assessment";
cmd.CommandType = CommandType.Text;
NpgsqlDataAdapter da = new NpgsqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
cmd.Dispose();
connection.Close();
GridView1.DataSource = dt;
GridView1.DataBind();
}
}
catch (Exception ex) { }
}
html代码为:`
<asp:TemplateField HeaderText="Delete">
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CommandName="delete">Delete</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField></Columns></asp:GridView> `
解决方案
推荐阅读
- c# - 制作日历并能够使用 c# 中的函数添加天/月/年
- javascript - 在 R 传单中使用 Java Script htmlwidget 指定点半径
- java - 为什么收不到数据
- c# - Visual Studio 2019 Intellisense 替换
- c - C fprintf and fscanf saving game state
- python - ruamel.yaml custom CommentedMapping 用于自定义标签
- java - 控制释放的键绑定不起作用
- javascript - 屏幕阅读器可访问的 React 图表库
- python - 查找图中顶点之间的所有路径
- maven - 未能执行目标 com.e-gineering:gitflow-helper-maven-plugin:2.2.0:enforce-versions