0

I connected windowsform with sql with ado and recive data in datagridview

for insert data i put textbox in my form but i tested it and put text but instead of set data into sql with sqlconnection(ado(connectionstring)) my boolean return false

private void btnsubmit_Click(object sender, EventArgs e) {
    if (ValidateInputs()) {
        bool isSuccess = repository.insert(
            txtname.Text, 
            txtfamily.Text, 
            txtemail.Text, 
            txtmobile.Text, 
            (int)txtage.Value, 
            txtadress.Text) ;
         
        if (isSuccess == true)
        {
            MessageBox.Show("Insert succeeded", "Success", MessageBoxButtons.OK,            MessageBoxIcon.Information);
            DialogResult = DialogResult.OK;
        }
        else {
            MessageBox.Show("Something went wrong","Error",MessageBoxButtons.OK);
        }

    }
}
RobIII
  • 8,488
  • 2
  • 43
  • 93
  • What if `ValidateInputs` returned false? What is `repository.insert`? – Zohar Peled Apr 10 '23 at 10:05
  • @ZoharPeled, even the code that shows a message box wouldn't get called because it's nested inside `ValidateInput` conditional structure – Son of Man Apr 10 '23 at 10:14
  • Given that the user is seeing a message box then that means `ValidateInputs` is returning true. The problem is with this line `repository. Insert() ` – Son of Man Apr 10 '23 at 10:15
  • @DongLi I'm well aware of that. this question was asked so that the OP will also realize that. – Zohar Peled Apr 10 '23 at 10:18
  • Use a `try and catch` block to catch the exception and message box it and then update your post to include that message. let's hope it's not a silent exception – Son of Man Apr 10 '23 at 10:18

0 Answers0