C# database question
Hey everyone Peebman2000, semi-beginner programmer. Practicing on C# and i'm trying to connect to the database, but its giving me an area for the datacommand.connection line. This is how I code in Vb.net and how I'm trying to code the database connection in C#.
Can someone show me why i'm getting and error on my datacommand.connection line? It seems to not like the connectionstrings(Peebman2000).
Thanks.
C# code
Code:
protected void Button1_Click(object sender, EventArgs e)
{
{
SqlDataAdapter dataadapter;
SqlCommand datacommand;
dataadapter = new SqlDataAdapter();
datacommand = new SqlCommand();
datacommand.Connection = new SqlConnection(ConfigurationManager.ConnectionStrings("peebman2000").ToString);
//datacommand.CommandText = "Insert INTO alerts (" + "title, " + "alert, " + "time)" + "values ('" + TextBox1.Text + "','" + "" + replaceQuotation(FreeTextBox1.Text) + "','" + "" + System.DateTime.Now + " ')";
//Response.Write(datacommand.CommandText.ToString)
//Response.End()
datacommand.Connection.Open();
try
{
datacommand.ExecuteNonQuery();
}
//Response.Write("data was entered")
catch (Exception ex)
{
//Response.Write("data not entered" & ex.ToString);
Response.End();
}
datacommand.Connection.Close();
}
}
peebman2000, April 21st, 2008 01:01 PM
Bookmarks