{
SqlConnection Con = new SqlConnection("Server=.;" + "database=Registration;"+"integrated Security=true;");
}
string Query = "Insert into[FormRegistration] values('1','dawood','Ahmed','Khan','Dubai','454','70','A')";
SqlCommand sqlCommand = new SqlCommand(Query,Con);
Con.Open();
int result = sqlCommand.ExecuteNonQuery();
Con.Close();
MessageBox.Show($"{result} rows inserted");
}
What I have tried:
private void btn_Click(object sender, EventArgs e)
{
string Error = "";
if (string.IsNullOrEmpty(txtbox1.Text))
{
Error = "Please Enter Valid Id";
}
if (string.IsNullOrEmpty(txtbox2.Text))
{
Error = "Please Enter Valid First Name";
}
if (string.IsNullOrEmpty(txtbox3.Text))
{
Error = "Please Enter MiddleName";
}
if (string.IsNullOrEmpty(txtbox4.Text))
{
Error = "Please Enter LastName";
}
if (string.IsNullOrEmpty(txtbox5.Text))
{
Error = "Please Enter Address";
}
if (string.IsNullOrEmpty(txtbox6.Text))
{
Error = "Please Enter Marks";
}
if (string.IsNullOrEmpty(txtbox7.Text))
{
Error = "Please Enter Percentage";
}
if (string.IsNullOrEmpty(txtbox8.Text))
{
Error = "Please Enter Grade";
}
if (Error.Length > 0)
{
MessageBox.Show(Error, "Validation Error", MessageBoxButtons.YesNo);
}
else
{
SqlConnection Con = new SqlConnection("Server=.;" + "database=Registration;"+"integrated Security=true;");
}
string Query = "Insert into[FormRegista] values('1','dawood','Ahmed','Khan','Dubai','454','70','A')";
SqlCommand sqlCommand = new SqlCommand(Query,Con);
Con.Open();
int result = sqlCommand.ExecuteNonQuery();
Con.Close();
MessageBox.Show($"{result} rows inserted