here table is creating but the values is not inserting
private void button_Click(object sender, EventArgs e)
{
SqlConnection cn;
cn = new SqlConnection("Data Source=.\\SQLEXPRESS;AttachDbFilename=J:\\Rcar\\motion\\db_image.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True");
if (cn.State==ConnectionState.Closed)
{
cn.Open();
}
SqlCommand cmd;
string sq1;
sq1 = "CREATE TABLE [" +Box1.Text+ "] (name CHAR(50) PRIMARY KEY," +"id CHAR(15), password CHAR(50), sex CHAR(10), email CHAR(15))";
cmd = new SqlCommand(sq1, cn);
try
{
cmd.ExecuteNonQuery();
MessageBox.Show("Table Created");
}
catch (SqlException sqlexception)
{
MessageBox.Show(sqlexception.Message, "Oh Fudge.",MessageBoxButtons.OK, MessageBoxIcon.Error);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Fooey.", MessageBoxButtons.OK,MessageBoxIcon.Error);
}
finally
{
cn.Close();
}
try
{
cn = new SqlConnection("Data Source=.\\SQLEXPRESS;AttachDbFilename=J:\\Rcar\\motion\\db_image.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True");
if (cn.State == ConnectionState.Closed)
{
cn.Open();
}
sq1 = "insert into [" + Box1.Text + "] values('" + accid.Text + "','" + pass.Text + "','" + sex.Text + "','" + email.Text + "')";
cmd = new SqlCommand(sq1, cn);
//cmd.ExecuteReader();
MessageBox.Show("User Saved", "User craetion", MessageBoxButtons.OK, MessageBoxIcon.Information);
cn.Close();
}
catch (Exception) { }
}