FMabey
asked on
Update SQL Server table with blanks
I have the following code which updates a SQL Server table from a windows application:
Private Sub SaveGAD()
If BOO_open = False Then
SqlConnection1.Open()
SQL_GAD_Update.Parameters( "@Cont").V alue = PUB_Cont
SQL_GAD_Update.Parameters( "@Str").Va lue = PUB_Str
SQL_GAD_Update.Parameters( "@Gdr").Va lue = "" & TXT_gdr1.Text & ""
SQL_GAD_Update.Parameters( "@GDP").Va lue = "" & TXT_cam.Text & ""
SQL_GAD_Update.Parameters( "@GCT").Va lue = "" & CB_cam2.Text & ""
SQL_GAD_Update.Parameters( "@GSAP").V alue = "" & TXT_subarc.Text & ""
SQL_GAD_Update.Parameters( "@GML").Va lue = "" & TXT_mag.Text & ""
SQL_GAD_Update.Parameters( "@GMF").Va lue = "" & TXT_magW.Text & ""
SQL_GAD_Update.Parameters( "@GD1").Va lue = "" & TXT_dpth2.Text & ""
SQL_GAD_Update.Parameters( "@GD2").Va lue = "" & TXT_dpth4.Text & ""
SQL_GAD_Update.Parameters( "@GDE1").V alue = "" & CB_dpth1.Text & ""
SQL_GAD_Update.Parameters( "@GDE2").V alue = "" & CB_dpth3.Text & ""
SQL_GAD_Update.Parameters( "@GN1").Va lue = "" & TXT_note6.Text & ""
SQL_GAD_Update.Parameters( "@GN2").Va lue = "" & TXT_note7.Text & ""
SQL_GAD_Update.Parameters( "@GN3").Va lue = "" & TXT_note8.Text & ""
SQL_GAD_Update.Parameters( "@GFN").Va lue = "" & TXT_fno.Text & ""
SQL_GAD_Update.Parameters( "@GRN").Va lue = "" & TXT_revno.Text & ""
If TXT_revdate.Text = "" Then
SQL_GAD_Update.Parameters( "@GRD").Va lue = System.DBNull.Value
Else
SQL_GAD_Update.Parameters( "@GRD").Va lue = "" & TXT_revdate.Text & ""
End If
SQL_GAD_Update.Parameters( "@GW").Val ue = False
SQL_GAD_Update.Parameters( "@GFCT").V alue = "" & TXT_cam3.Text & ""
SQL_GAD_Update.Parameters( "@GFCB").V alue = "" & TXT_cam4.Text & ""
SQL_GAD_Update.ExecuteNonQ uery()
SqlConnection1.Close()
End If
End Sub
Currently, if a textbox is empty, the SQL Server table gets updated with a blank cell. My question is, should I be checking if the text box is empty with an if statement for each parameter (similar to the if statement for the @GRD parameter shown above), and then insert a system.dbnull.value?
Cheers
Private Sub SaveGAD()
If BOO_open = False Then
SqlConnection1.Open()
SQL_GAD_Update.Parameters(
SQL_GAD_Update.Parameters(
SQL_GAD_Update.Parameters(
SQL_GAD_Update.Parameters(
SQL_GAD_Update.Parameters(
SQL_GAD_Update.Parameters(
SQL_GAD_Update.Parameters(
SQL_GAD_Update.Parameters(
SQL_GAD_Update.Parameters(
SQL_GAD_Update.Parameters(
SQL_GAD_Update.Parameters(
SQL_GAD_Update.Parameters(
SQL_GAD_Update.Parameters(
SQL_GAD_Update.Parameters(
SQL_GAD_Update.Parameters(
SQL_GAD_Update.Parameters(
SQL_GAD_Update.Parameters(
If TXT_revdate.Text = "" Then
SQL_GAD_Update.Parameters(
Else
SQL_GAD_Update.Parameters(
End If
SQL_GAD_Update.Parameters(
SQL_GAD_Update.Parameters(
SQL_GAD_Update.Parameters(
SQL_GAD_Update.ExecuteNonQ
SqlConnection1.Close()
End If
End Sub
Currently, if a textbox is empty, the SQL Server table gets updated with a blank cell. My question is, should I be checking if the text box is empty with an if statement for each parameter (similar to the if statement for the @GRD parameter shown above), and then insert a system.dbnull.value?
Cheers
ASKER
Yes, I mean a zero-length string and yes, the database does allow nulls. The designer does not want to do anything with the nulls... If it's empty, it's empty. I was just curious as to how best handle this.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Good, clear explainations
ASKER
Cheers dportas,
I understand much better now. I'll take it on from here.
I understand much better now. I'll take it on from here.
This is really a database modeling question. Does your database allow nulls and if so what is the designer's intended meaning for nulls in the database? The topic of whether and when to use nulls at all is a big one and probably not something we can do justice to in this forum.