I have been trying to insert null into database but every time I am getting failed. I tried several codes but nothing is working. When I tried this code:
If String.IsNullOrEmpty(TextBox2.Text) Then
TextBox2.Text = DBNull.Value
Else
TextBox2.Text = TextBox2.Text
End If
It gives me an error :
Value of type 'System.DBNull' cannot be converted to 'String'.
And when I tried this:
If Not String.IsNullOrEmpty(TextBox2.Text) = True Then
TextBox2 = System.DBNull.Value
Else
TextBox2.Text = TextBox2.Text
End If
It gives me an error:
Value of type 'System.DBNull' cannot be converted to 'System.Windows.Forms.TextBox'.
Before these code I have added some validations in order to make the text box compulsory to filled by the user.
This is the place where I am getting this error:
dsNewRow.Item("emp_name") = TextBox1.Text
dsNewRow.Item("emp_age") = TextBox2.Text 'This is the place where I am getting this error'
dsNewRow.Item("emp_gend") = ComboBox1.Text
dsNewRow.Item("emp_dob") = DateTimePicker1.Text
dsNewRow.Item("emp_mstatus") = TextBox4.Text
dsNewRow.Item("emp_qual") = RichTextBox1.Text
dsNewRow.Item("emp_exp") = RichTextBox2.Text
It also shows:
Input string was not in a correct format.Couldn't store <> in emp_age Column. Expected type is Int32.