Click here to Skip to main content
15,905,616 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
So here is my problem, when I run my code I get there is already an object named 'blank" in the database, but when I go to check to see what was added into the table it only accepts 1 of the checked box items. Can someone help me with this issue please

For Each list As String In CheckedListBox1.CheckedItems

               CheckState.Checked.ToString()

               sqlcon.Open()
               Dim cmd As SqlClient.SqlCommand
               Dim sql As String = "CREATE TABLE" + "[" + St + "]" + "(Id INTEGER Not Null PRIMARY KEY CLUSTERED ([Id] ASC)," + list.ToString + " NVARCHAR (MAX) NULL)"
               cmd = New SqlClient.SqlCommand(sql, sqlcon)


What I have tried:

I have tried to switch the for each statement to a selecteditems for each statement. which didnt work.
Posted
Updated 25-Jan-17 0:54am
Comments
Michael_Davies 25-Jan-17 6:28am    
This statement has no effect: CheckState.Checked.ToString()

It returns a value (string) that should be assigned to a variable normally, you are not doing anything with it.

Use the debugger and look at the value of list in each iteration.

1 solution

The problem is that you are trying to create the same table over and over again: all with the same table name. SQL won't let you do that: you cannot have two tables with the same name as SQL wouldn't know which one you were referring to when you tried to access one of them.
 
Share this answer
 
Comments
Member 11856456 25-Jan-17 13:29pm    
how can I rearrange my code to where I am saying that these checked items are used to create the columns of my table. That's mainly all I am trying to do is use the text to create columns based upon what the user has selected?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900