G
Grecko
Hi all
I am having an insert problem with values of different data types. I
have a form that has text boxes accepting information that goes into a
table with String int & decimal data types.
I have used the convert.toInt and convert.toDecimal but i am having
trouble building the SQL statement
Here is a sample of my code
*****************************************************
Private Sub btnInsert_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnInsert.Click
Dim strSQL As String
Dim strCnn As String
'create a connection string to connect to the database
strCnn = BuildCnnStr("MainPC", "SDSDatabase")
'create the connection
Dim cn As New OleDb.OleDbConnection(strCnn)
'conection is open
cn.Open()
'set up the sql string to insert the values collected from the
Text Boxes
strSQL = "INSERT into inletCone( DrawingID, SupplierID,
Internal_Code, " & _
"Model_Number, Description, Diameter, Angle_Of_Intake," & _
"Mass, Flange_Dimensions, No_Of_Holes, Notes) " & _
"Values( Convert.ToInt32(txtDrawingID.Text) & _
Convert.ToInt32(txtSupplierID.Text)& _
Convert.ToInt32(txtInternalCode.Text)& _
" '" & txtModelNumber.Text & " ' " , & _
" '" & txtDescription.Text & "' ", & _
Convert.ToDecimal(txtDiameter.Text) & ", " & _
Convert.ToDecimal(txtIntake.Text) & , & _
Convert.ToDecimal(txtMass.Text) & " , " & _
Convert.ToDecimal(txtFlangeDimension.Text) & " , " & _
Convert.ToDecimal(txtNo_Of_Holes.Text) & " , " & _
" '" & rtbNotes.Text & " ')"
'create a command object
Dim cmd As OleDb.OleDbCommand
' set the object as create command
cmd = cn.CreateCommand()
' strSQL is the insert statement
cmd.CommandText = strSQL
cmd.Connection = cn
cmd = New OleDb.OleDbCommand(strSQL, cn)
cmd.ExecuteNonQuery()
***********************************************************************
The text books i have used seem to just show all string values in thier
Query statements.
Am i approaching this the right way or is there a better approach
Thanks in advance
Greg
I am having an insert problem with values of different data types. I
have a form that has text boxes accepting information that goes into a
table with String int & decimal data types.
I have used the convert.toInt and convert.toDecimal but i am having
trouble building the SQL statement
Here is a sample of my code
*****************************************************
Private Sub btnInsert_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnInsert.Click
Dim strSQL As String
Dim strCnn As String
'create a connection string to connect to the database
strCnn = BuildCnnStr("MainPC", "SDSDatabase")
'create the connection
Dim cn As New OleDb.OleDbConnection(strCnn)
'conection is open
cn.Open()
'set up the sql string to insert the values collected from the
Text Boxes
strSQL = "INSERT into inletCone( DrawingID, SupplierID,
Internal_Code, " & _
"Model_Number, Description, Diameter, Angle_Of_Intake," & _
"Mass, Flange_Dimensions, No_Of_Holes, Notes) " & _
"Values( Convert.ToInt32(txtDrawingID.Text) & _
Convert.ToInt32(txtSupplierID.Text)& _
Convert.ToInt32(txtInternalCode.Text)& _
" '" & txtModelNumber.Text & " ' " , & _
" '" & txtDescription.Text & "' ", & _
Convert.ToDecimal(txtDiameter.Text) & ", " & _
Convert.ToDecimal(txtIntake.Text) & , & _
Convert.ToDecimal(txtMass.Text) & " , " & _
Convert.ToDecimal(txtFlangeDimension.Text) & " , " & _
Convert.ToDecimal(txtNo_Of_Holes.Text) & " , " & _
" '" & rtbNotes.Text & " ')"
'create a command object
Dim cmd As OleDb.OleDbCommand
' set the object as create command
cmd = cn.CreateCommand()
' strSQL is the insert statement
cmd.CommandText = strSQL
cmd.Connection = cn
cmd = New OleDb.OleDbCommand(strSQL, cn)
cmd.ExecuteNonQuery()
***********************************************************************
The text books i have used seem to just show all string values in thier
Query statements.
Am i approaching this the right way or is there a better approach
Thanks in advance
Greg