I'm trying to add the values / the text the user input from my textboxs into my database.
At the moment I can't get the code to insert the values to the sqldatabase.
Here is my aspx Code
<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" />
Here is my C# code:
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();
}
}
}
}
}
I tried other links from stackoverflow but can't seem to find anything that makes this work.
Hope you can help me. I'm sorry if I'm doing this in a strange way.