473,322 Members | 1,431 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Insert null values into database vb.net

ayakamacy
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.
May 22 '15 #1

✓ answered by ayakamacy

I knew the answer for this problem.
for those people who will encounter this problem

Try this sample code, and its working =)

Expand|Select|Wrap|Line Numbers
  1.  
  2. Dim cmd As New SqlCommand("SELECT * FROM tblJOL", SQLcon)
  3. cmd.Parameters.Add(New SqlParameter("@DRsda", SqlDbType.VarChar))
  4. If (txtShipoutDateActual.Text = "") Then
  5.    cmd.Parameters("@DRsda").Value = DBNull.Value
  6. Else
  7.    Dim dateValueSDA As Date
  8.    dateValueSDA = txtShipoutDateActual.Text
  9.    lblDaysda.Text = WeekdayName(Weekday(dateValueSDA))
  10. End If
  11.  

3 4865
computerfox
276 100+
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?
May 22 '15 #2
i only used varchar(MAX)
as I've said above, when the time i left txtShipoutDateActual.Text empty, i got an error. "Conversion from string "" to type 'Date' is not valid."
because all the input value of txtShipoutDateActual.Text i convert it into Dayvalue.
here is my code:
Expand|Select|Wrap|Line Numbers
  1. Dim dateValueSDA As Date
  2. dateValueSDA = txtShipoutDateActual.Text
  3. lblDaysda.Text = WeekdayName(Weekday(dateValueSDA))
  4.  
How can i code that into a conditional statement if txtShipoutDateActual.Text is null value, and lblDaysda.Text should also null value to save in database.
May 22 '15 #3
I knew the answer for this problem.
for those people who will encounter this problem

Try this sample code, and its working =)

Expand|Select|Wrap|Line Numbers
  1.  
  2. Dim cmd As New SqlCommand("SELECT * FROM tblJOL", SQLcon)
  3. cmd.Parameters.Add(New SqlParameter("@DRsda", SqlDbType.VarChar))
  4. If (txtShipoutDateActual.Text = "") Then
  5.    cmd.Parameters("@DRsda").Value = DBNull.Value
  6. Else
  7.    Dim dateValueSDA As Date
  8.    dateValueSDA = txtShipoutDateActual.Text
  9.    lblDaysda.Text = WeekdayName(Weekday(dateValueSDA))
  10. End If
  11.  
May 23 '15 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

10
by: Python_it | last post by:
Python 2.4 MySQL-python.exe-1.2.0.win32-py2.4.zip How can I insert a NULL value in a table (MySQL-database). I can't set a var to NULL? Or is there a other possibility? My var must be variable...
3
by: Rodrigo C. Souza | last post by:
I need to insert a null value in a table on MS SQL Server 2000 using a stored procedure. When I send no data to the stored procedure, I get an error saying that the value cannot be null, but I did...
2
by: hellrazor | last post by:
Hi there, I have the following INSERT statement: fieldOne is of type int fieldTwo is of type date In MySQL, both are allowed to hold null values. Now, I try to insert regular data into...
2
by: Patrick Olurotimi Ige | last post by:
How can i insert NULL below? It says i can;t convert it to character!! Dim MB As Char If Request.Params("MB") = "True" Then MB = "Y" ElseIf Request.Params("MB") = "False" Then MB = "N" Else...
11
by: Bllich | last post by:
hy, I have int column 'number' in my table that allowes nulls when I instance a dataTable in my winform app. and I want to do table.AddTableRow(string name, int number); I need to send null...
2
by: teddysnips | last post by:
I have an application that does some data manipulation of some tables to format a table for a report. 1. First I open the table that gives me the parameters for some later queries strSQL =...
1
by: praveena mani | last post by:
Can we insert null values in stored procedures? When we tried to insert null inprocedures its giving query ok... But wen we try to display the values from table it shows empty set... Y???
3
by: anandmms | last post by:
Hello friends, I am having a table Personal_Detail, and in that table i am having some fields like name, id, phone_number etc... and also with two blob fields photo1, photo2(allow null). my...
1
by: Bigdaddrock | last post by:
I am attempting to concatenate LName and FName into an expression I will call TelName. If there is no LName, I would like to just have FName appear. If there is no FName I would like just LName to...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.