A
Age
I need help.
I am trying to figure out the best way to uodate a database with
information. I am gathering my information from text fields on a form
and I just want to insert them into the database that I have.
I tried builing the SQL string and then adding it to a command object
and then executing a non query but .NET does not seem to like this
approach. I have been reviewing the various VB .NET manuals and they
seem to want me to fill a dataset. Can this be done without the
dataset?
Would I be better off just sticking with regular ADO for this kind of
operation?
I was trying something like the following and getting errors:
Dim cn As OdbcConnection
cn = New OdbcConnection("dsn=CMI;uid=;pwd=;")
strSQL = "INSERT INTO Customer
_(FirstName,LastName,Address,City,Province,PostalCode,Email)"
strSQL += " VALUES ('"
strSQL += "'" & Replace(txtFirstName.Text, "'", "''") & "',"
strSQL += "'" & Replace(txtLastName.Text, "'", "''") & "',"
strSQL += "'" & Replace(txtAddress.Text, "'", "''") & "',"
strSQL += "'" & Replace(txtCity.Text, "'", "''") & "',"
strSQL += "'" & Replace(txtProvince.Text, "'", "''") & "',"
strSQL += "'" & Replace(txtPostal.Text, "'", "''") & "',"
strSQL += "'" & Replace(txtEmail.Text, "'", "''") & "')"
cn.Open()
Dim cmdInsertCustomer As New OdbcCommand(strSQL, cn)
cmdInsertCustomer.ExecuteNonQuery()
cn.Close()
Can anyone suggest a way I could accomplish what I need to do here.
Many thanks.
I am trying to figure out the best way to uodate a database with
information. I am gathering my information from text fields on a form
and I just want to insert them into the database that I have.
I tried builing the SQL string and then adding it to a command object
and then executing a non query but .NET does not seem to like this
approach. I have been reviewing the various VB .NET manuals and they
seem to want me to fill a dataset. Can this be done without the
dataset?
Would I be better off just sticking with regular ADO for this kind of
operation?
I was trying something like the following and getting errors:
Dim cn As OdbcConnection
cn = New OdbcConnection("dsn=CMI;uid=;pwd=;")
strSQL = "INSERT INTO Customer
_(FirstName,LastName,Address,City,Province,PostalCode,Email)"
strSQL += " VALUES ('"
strSQL += "'" & Replace(txtFirstName.Text, "'", "''") & "',"
strSQL += "'" & Replace(txtLastName.Text, "'", "''") & "',"
strSQL += "'" & Replace(txtAddress.Text, "'", "''") & "',"
strSQL += "'" & Replace(txtCity.Text, "'", "''") & "',"
strSQL += "'" & Replace(txtProvince.Text, "'", "''") & "',"
strSQL += "'" & Replace(txtPostal.Text, "'", "''") & "',"
strSQL += "'" & Replace(txtEmail.Text, "'", "''") & "')"
cn.Open()
Dim cmdInsertCustomer As New OdbcCommand(strSQL, cn)
cmdInsertCustomer.ExecuteNonQuery()
cn.Close()
Can anyone suggest a way I could accomplish what I need to do here.
Many thanks.