rectified codes.
public void ConnecttoDb()
{
string myconn;
myconn = "Data Source=.\SQLEXPRESS;AttachDbFilename=" + Application.StartupPath + "\Data.mdf;Integrated Security=True;User Instance=True";
con = new SqlConnection(myconn);
con.open(); cmd.Connection = con;
try
{
//cmd = new SqlCommand("select name from comp",con);
MessageBox.Show("Connect Success","Database",MessageBoxButtons.OKCancel);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
insert statement
private void btnInsert_Click(object sender, EventArgs e)
{
cmd.CommandText = insert into comp values ("'" + tbNo.Text + ",'" + tbName.Text + "') ";
cmd.CommandType = cmd.CommandType.CommandText;
try
{
cmd.ExecuteNonQuery();
MessageBox.Show("Insert Done...", "Insert");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error");
}
}