I am working on Visual Studio 2013.
In the below code the MessageBox.Show("Connected to database") is shown correctly, but the SQL query is not inserting data into the database table.
When I insert data manually then it inserts without any problems. But unfortunately the data fails to insert on the button_click command.
private void DataAdd_Load(object sender, EventArgs e)
{
try
{
conn = new SqlConnection("Data Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename=Pathname;Integrated Security=True;Connect Timeout=30");
conn.Open();
MessageBox.Show("Connected to database");
cmd = new SqlCommand("INSERT INTO datains (name, dob, gender, occupation, height, weight, relation, polexpo) values('abc', '22-Aug-2001', 'Male', 'qwe2', '23', '431', 'qw23e', 'asqwed');", conn);
}
catch (Exception e1)
{
MessageBox.Show("Connection failed");
}
}
What have I done wrong here or anything I have missed?