gpt4 book ai didi

c# - 将文本框中的文本插入数据库

转载 作者:太空宇宙 更新时间:2023-11-03 20:10:12 24 4
gpt4 key购买 nike

<分区>

我正在尝试将用户从我的文本框中输入的值/文本添加到我的数据库中。

目前我无法获得将值插入 sql 数据库的代码。

这是我的aspx代码

<asp:TextBox ID="txt_WineName" runat="server" PlaceHolder="WineName" />
<asp:TextBox ID="txt_WineYear" runat="server" PlaceHolder="WineYear" />
<asp:TextBox ID="txt_WinePrice" runat="server" PlaceHolder="WinePrice" />
<asp:TextBox ID="txt_WineType" runat="server" PlaceHolder="WineType" />
<asp:Button ID="btn_AddWine" runat="server" Text="Add" />

这是我的 C# 代码:

protected void btn_AddWine(object sender, EventArgs e)
{
using (SqlConnection connection = new SqlConnection("Data Source=PCM13812;Initial Catalog=Kronhjorten;Integrated Security=True"))
{
connection.Open();
string query = "SELECT * FROM Wines";
using (SqlCommand command = new SqlCommand(query, connection))
{
using (SqlDataReader reader = command.ExecuteReader())
{
while (reader.Read())
{
string Name = txt_WineName.Text;
string Year = txt_WineYear.Text;
string Price = txt_WinePrice.Text;
string Type = txt_WineType.Text;
Sql_Insert.Insert();
}
}
}
}
}

我尝试了来自 stackoverflow 的其他链接,但似乎无法找到使这项工作有效的任何内容。

希望你能帮助我。如果我以一种奇怪的方式这样做,我很抱歉。

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com