I am trying to learn how to take control values and insert them into a db table. For example I have a textbox called NameBox. I want to grab the text from that textbox and add it into a database table.
I am not trying to do it the best way but the simplest so I can wrap by head around the concept. So far I have:
<asp:TextBox ID="NameBox" runat="server"></asp:TextBox>
<asp:TextBox ID="EmailBox" runat="server"></asp:TextBox>
Here is the code-behind.
protected void Button1_Click(object sender, EventArgs e)
{
string name1 = NameBox.Text;
string email1 = EmailBox.Text;
System.Data.SqlClient.SqlConnection sqlConnection1 =
new System.Data.SqlClient.SqlConnection(@"Data Source=E:\*********.com1.5\**********.com\App_Data\Home.sdf;");
System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand();
cmd.CommandType = System.Data.CommandType.Text;
cmd.CommandText = "INSERT INTO CustomerList (Name, Email) VALUES (" + name1 + "," + email1 + ")";
cmd.Connection = sqlConnection1;
sqlConnection1.Open();
cmd.ExecuteNonQuery();
sqlConnection1.Close();
}
Error message I am getting is
A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)
I googled the error message and a lot of what i been reading is saying my connection is probably wrong. I tried testing this by using some of the drag and drop controls and I have a repeater working with the same connection string.
Right now I don't even really know if this is right approach. As I am sure you can all relate at one point or another I want to see it work on a very simple level so i can start to play with it and see how it all really works.