【发布时间】:2013-12-11 19:45:08
【问题描述】:
我正在尝试将用户从我的文本框中输入的值/文本添加到我的数据库中。
目前我无法获取将值插入到 sqldatabase 的代码。
这是我的 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 中的其他链接,但似乎找不到任何可以实现此功能的链接。
希望你能帮助我。如果我以一种奇怪的方式这样做,我很抱歉。
【问题讨论】: