Good Day ! i'm here again ;) i will just ask , how will i disable saving on my database if the textboxes and the comboboxes are empty . it's just that everytime i click the button 'save' it saves even the fields are empty . i already put msgbox on the code saying that 'pls fill out fields' but after that it'll save. all i want to do is, if i click save and the fields are empty it'll not save and pops up a msgbox saying 'plss fill out fields' and if i put data on fields it'll save now :)
here is the code:
Dim command As New OleDbCommand("insert into confiscation(num,REGION,PENRO,CENRO,MONTHDATE,YEARDATE,CONVEYANCE,CONV_UNITOFMEASURE,CONV_EST_VALUE,CHAINSAW,CHAIN_UNITOFMEASURE,CHAIN_EST_VALUE,LOGS,LOGS_UNITOFMEASURE,LOGS_EST_VALUE,FLITCHES,FLITCH_UNITOFMEASURE,FLITCH_EST_VALUE,LUMBER,LUMB_UNITOFMEASURE,LUMB_EST_VALUE) values (@num,@REGION,@PENRO,@CENRO,@MONTHDATE,@YEARDATE,@CONVEYANCE,@CONV_UNITOFMEASURE,@CONV_EST_VALUE,@CHAINSAW,@CHAIN_UNITOFMEASURE,@CHAIN_EST_VALUE,@LOGS,@LOGS_UNITOFMEASURE,@LOGS_EST_VALUE,@FLITCHES,@FLITCH_UNITOFMEASURE,@FLITCH_EST_VALUE,@LUMBER,@LUMB_UNITOFMEASURE,@LUMB_EST_VALUE)")
command.CommandType = CommandType.Text
con.Open()
If TextBox1.Text = "" And TextBox3.Text = "" _
And TextBox5.Text = "" And TextBox7.Text = "" _
And TextBox9.Text = "" Then
MsgBox("cannot be saved, please fill the confiscated product")
Else
With command.Parameters
.AddWithValue("@num,", a)
.AddWithValue("@REGION,", ComboBox1.Text)
.AddWithValue("@PENRO,", ComboBox2.Text)
.AddWithValue("@CENRO,", ComboBox3.Text)
.AddWithValue("@MONTHDATE,", ComboBox4.Text)
.AddWithValue("@YEARDATE,", TextBox11.Text)
.AddWithValue("@CONVEYANCE,", TextBox1.Text)
.AddWithValue("@CONV_UNITOFMEASURE,", ComboBox5.Text)
.AddWithValue("@CONV_EST_VALUE,", TextBox2.Text)
.AddWithValue("@CHAINSAW,", TextBox3.Text)
.AddWithValue("@CHAIN_UNITOFMEASURE,", ComboBox6.Text)
.AddWithValue("@CHAIN_EST_VALUE,", TextBox4.Text)
.AddWithValue("@LOGS,", TextBox5.Text)
.AddWithValue("@LOGS_UNITOFMEASURE,", ComboBox7.Text)
.AddWithValue("@LOGS_EST_VALUE,", TextBox6.Text)
.AddWithValue("@FLITCHES,", TextBox7.Text)
.AddWithValue("@FLITCH_UNITOFMEASURE,", ComboBox8.Text)
.AddWithValue("@FLITCH_EST_VALUE,", TextBox8.Text)
.AddWithValue("@LUMBER,", TextBox9.Text)
.AddWithValue("@LUMB_UNITOFMEASURE,", ComboBox9.Text)
.AddWithValue("@LUMB_EST_VALUE,", TextBox10.Text)
End With
command.Connection = con
command.ExecuteNonQuery()
con.Close()
MsgBox("success")
ComboBox1.SelectedIndex = -1
ComboBox2.SelectedIndex = -1
ComboBox3.SelectedIndex = -1
ComboBox4.SelectedIndex = -1
ComboBox5.SelectedIndex = -1
ComboBox6.SelectedIndex = -1
ComboBox7.SelectedIndex = -1
ComboBox8.SelectedIndex = -1
ComboBox9.SelectedIndex = -1
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""
TextBox5.Text = ""
TextBox6.Text = ""
TextBox7.Text = ""
TextBox8.Text = ""
TextBox9.Text = ""
TextBox10.Text = ""
TextBox11.Text = ""
datagrid_add()
count()
End If
End Sub
any answer may help so much :)
Thanks in advance,