Im doing a simple form of 21 fields that rights to a sql table.
my issue is i cant get it to work unless i have all variables as strings and strings fields in my tables.
here is my code and if i try to put in a field as integer or date it errors out. Im using VS 2008
my variables
Dim strinjnumber As String
Dim strEmpID As String
Dim dtInjDate As String 'dates
Dim dtInjTime As String 'dates
Dim strOsha As String
Dim strinjLoc As String
Dim strspecloc As String
Dim strbodypart As String
Dim strinjnature As String
Dim strrootcause As String
Dim strinjcause As String
Dim strsafeprov As String
Dim strsafeused As String
Dim strtreatment As String
Dim strmissed As String
Dim strrestricted As String
Dim strwhathappend As String
Dim strcorrective As String
Dim strdeptid As String
Dim strshift As String
Dim strhoursintoshift As String
my code:
Dim sqlcon As New SqlConnection("server=tpmpi01;database=vq-dsi;uid=bk;password=valley")
'checking if connection is open. if open close it and open again.
If sqlcon.State = ConnectionState.Open Then
sqlcon.Close()
End If
sqlcon.Open()
Dim strcommand As String
'the insert command is stored in strcommand
'Table Name : Contact
'Column of table : Name, Place
strcommand = "Insert into Injury(injnmbr, empID, injdate, injtime,osha, injLoc, specloc, bodypart, injnature,rootcause, injcause, safeguardsprovided, safeguardsused, treatment, daysmissed, daysrestricted, whathappend, correctiveaction, deptid, shift, hoursintoshift) values ('" + strinjnumber + "','" + strEmpID + "','" + dtInjDate + "','" + dtInjTime + "','" + strOsha + "','" + strinjLoc + "','" + strspecloc + "','" + strbodypart + "','" + strinjnature + " ','" + strrootcause + "','" + strinjcause + "','" + strsafeprov + "','" + strsafeused + "','" + strtreatment + "','" + strmissed + "','" + strrestricted + "','" + strwhathappend + "','" + strcorrective + "','" + strdeptid + "','" + strshift + "','" + strhoursintoshift + "')"
my issue is i cant get it to work unless i have all variables as strings and strings fields in my tables.
here is my code and if i try to put in a field as integer or date it errors out. Im using VS 2008
my variables
Dim strinjnumber As String
Dim strEmpID As String
Dim dtInjDate As String 'dates
Dim dtInjTime As String 'dates
Dim strOsha As String
Dim strinjLoc As String
Dim strspecloc As String
Dim strbodypart As String
Dim strinjnature As String
Dim strrootcause As String
Dim strinjcause As String
Dim strsafeprov As String
Dim strsafeused As String
Dim strtreatment As String
Dim strmissed As String
Dim strrestricted As String
Dim strwhathappend As String
Dim strcorrective As String
Dim strdeptid As String
Dim strshift As String
Dim strhoursintoshift As String
my code:
Dim sqlcon As New SqlConnection("server=tpmpi01;database=vq-dsi;uid=bk;password=valley")
'checking if connection is open. if open close it and open again.
If sqlcon.State = ConnectionState.Open Then
sqlcon.Close()
End If
sqlcon.Open()
Dim strcommand As String
'the insert command is stored in strcommand
'Table Name : Contact
'Column of table : Name, Place
strcommand = "Insert into Injury(injnmbr, empID, injdate, injtime,osha, injLoc, specloc, bodypart, injnature,rootcause, injcause, safeguardsprovided, safeguardsused, treatment, daysmissed, daysrestricted, whathappend, correctiveaction, deptid, shift, hoursintoshift) values ('" + strinjnumber + "','" + strEmpID + "','" + dtInjDate + "','" + dtInjTime + "','" + strOsha + "','" + strinjLoc + "','" + strspecloc + "','" + strbodypart + "','" + strinjnature + " ','" + strrootcause + "','" + strinjcause + "','" + strsafeprov + "','" + strsafeused + "','" + strtreatment + "','" + strmissed + "','" + strrestricted + "','" + strwhathappend + "','" + strcorrective + "','" + strdeptid + "','" + strshift + "','" + strhoursintoshift + "')"