troubleshooting Question

how to write to a database using and multiple columns.

Avatar of cmdolcet
cmdolcetFlag for United States of America asked on
Visual Basic.NET
15 Comments3 Solutions103 ViewsLast Modified:
I am trying to write to a database using the following code. The code below works just fine, but how can I write an unknown amount of columns to a table?

So after the barcode I would need to write up to 47 new columns.

 Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim conStr As String = "SERVER=PC167\DBTEST;Database =ORKA Test; trusted_connection= yes"
        Dim objcon As New SqlConnection(conStr)
        Dim obj As SqlCommand
        Dim strSQL As String
        Dim DoesTableExist As Boolean
        If (objcon.State = ConnectionState.Open) Then
        End If
        If objcon.Database = "ORKA Test" Then
            MessageBox.Show("Database Exists")
        End If
        obj = objcon.CreateCommand()
        strSQL = "CREATE TABLE  DATA3" + "(Time VARCHAR(30), Date VARCHAR(30),Barcode VARCHAR (30))"
        obj.CommandText = strSQL
    End Sub
Join our community to see this answer!
Unlock 3 Answers and 15 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 3 Answers and 15 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros