Hello all, i was wondering how should i insert null values into a database. I have textbox1 and the textbox2 will convert the value out of textbox1, when i the time i click save and the textbox1 is empty i got an error, "Conversion from string "" to type 'Date' is not valid." i just want to insert null value if the textbox is empty.
Insert null values into database vb.net
Collapse
X
-
What the data type in the database?
Can you update the column to default null?
Are you doing any verification in your code?
By the looks of it, the column currently is set to a date type, is this correct? -
i only used varchar(MAX)
as I've said above, when the time i left txtShipoutDateA ctual.Text empty, i got an error. "Conversion from string "" to type 'Date' is not valid."
because all the input value of txtShipoutDateA ctual.Text i convert it into Dayvalue.
here is my code:
Code:Dim dateValueSDA As Date dateValueSDA = txtShipoutDateActual.Text lblDaysda.Text = WeekdayName(Weekday(dateValueSDA))
Comment
-
Best answer
I knew the answer for this problem.
for those people who will encounter this problem
Try this sample code, and its working =)
Code:Dim cmd As New SqlCommand("SELECT * FROM tblJOL", SQLcon) cmd.Parameters.Add(New SqlParameter("@DRsda", SqlDbType.VarChar)) If (txtShipoutDateActual.Text = "") Then cmd.Parameters("@DRsda").Value = DBNull.Value Else Dim dateValueSDA As Date dateValueSDA = txtShipoutDateActual.Text lblDaysda.Text = WeekdayName(Weekday(dateValueSDA)) End If
Comment
Comment