Insert problem !!

From: Grecko (oldgradgrego_at_netscape.net)
Date: 07/08/04


Date: Thu, 08 Jul 2004 17:50:47 +0800

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



Relevant Pages

  • Re: Converting a number to Text
    ... I'm having a tough time with my SQL statement when I try to join two ... your text is not very long, if all you expect to do with it is to compare it ... comparing different data types (and in particular, ...
    (comp.databases.informix)
  • Re: Inserting empty items into a field.
    ... DENSITY] are double data types.) ... empty/null. ... deleting the entry in those fields but how do I do it with the SQL statement. ... MVP ...
    (microsoft.public.access.modulesdaovba)
  • SQL statement question
    ... I am updating a table using the following SQL statement: ... They are both text data types. ... are supposed to be two digits. ...
    (microsoft.public.access.formscoding)
  • Re: Insert problem !!
    ... > I am having an insert problem with values of different data types. ... Check out .net help on SqlParameter class for example. ...
    (microsoft.public.dotnet.framework.adonet)
  • Converting a number to Text
    ... I'm having a tough time with my SQL statement when I try to join two ... data types not being equal. ... Chaim Bochner ...
    (comp.databases.informix)