Ignoring the typos in your question, you've declared a
SqlConnection
variable, but you haven't actually set it to anything before you try to call a method on it.
Also, your code is susceptible to
SQL Injection[
^]. You should be using parameterized queries instead of string concatenation.
if (radioButton1.Checked)
{
using (SqlConnection sqlconn = new SqlConnection("YOUR CONNECTION STRING HERE"))
using (SqlCommand sqlcmd = sqlconn.CreateCommand())
{
sqlcmd.CommandText = "insert into GI_sub0 values (@p0, @p1, @p2, @p3, @p4, @p5)";
sqlcmd.Parameters.AddWithValue("@p0", "001");
sqlcmd.Parameters.AddWithValue("@p1", textBox1.Text);
sqlcmd.Parameters.AddWithValue("@p2", textBox2.Text);
sqlcmd.Parameters.AddWithValue("@p3", "admin");
sqlcmd.Parameters.AddWithValue("@p4", new DateTime(2011, 3, 4));
sqlcmd.Parameters.AddWithValue("@p5", "10");
try
{
sqlconn.Open();
sqlcmd.ExecuteNonQuery();
MessageBox.Show("Record Entered Successfull");
}
catch (SqlException err)
{
MessageBox.Show(err.Message);
}
}
}