Need help copying listbox items to database table

  • Thread starter Thread starter Loogie
  • Start date Start date
L

Loogie

I am using VB.Net 2005 Compact Framework with SQL CE Server.

I am attempting to add the entire contents of a listbox to a SQL CE
Server database but my code is throwing an error and I do not know how
to fix it.

Here is my code:

'Create product species table
sqlCreateTable.CommandText = "CREATE TABLE prodspecies(s_item
int IDENTITY(1,1) PRIMARY KEY NOT NULL, s_code NVARCHAR(10) NOT NULL,
s_link NVARCHAR(3) NOT NULL, s_verify NVARCHAR(3) NULL)"
sqlCreateTable.ExecuteNonQuery()

Dim X As Integer
X = 0

Dim sqlInsertRow2 As SqlCeCommand = ssceconn.CreateCommand()
Do Until X = lstOut.Items.Count
Dim strsqlSPEC As String = "INSERT INTO prodspecies(s_code,
s_link) VALUES('" & lstIn.Items.Add(lstOut.Items.Item(X)) & "', '" &
cboCode.SelectedItem.ToString & "')"
sqlInsertRow2.ExecuteNonQuery()
X = X + 1
Loop

Details of error:

System.InvalidOperationException was unhandled
Message="Prepare: CommandText property has not been initialized"

Error occurs on line: sqlInsertRow2.ExecuteNonQuery()

Please help me fix this.

Thanks

:L
 
Loogie said:
I am using VB.Net 2005 Compact Framework with SQL CE Server.

I am attempting to add the entire contents of a listbox to a SQL CE
Server database but my code is throwing an error and I do not know how
to fix it.

Here is my code:

'Create product species table
sqlCreateTable.CommandText = "CREATE TABLE prodspecies(s_item
int IDENTITY(1,1) PRIMARY KEY NOT NULL, s_code NVARCHAR(10) NOT NULL,
s_link NVARCHAR(3) NOT NULL, s_verify NVARCHAR(3) NULL)"
sqlCreateTable.ExecuteNonQuery()

Dim X As Integer
X = 0

Dim sqlInsertRow2 As SqlCeCommand = ssceconn.CreateCommand()
Do Until X = lstOut.Items.Count
Dim strsqlSPEC As String = "INSERT INTO prodspecies(s_code,
s_link) VALUES('" & lstIn.Items.Add(lstOut.Items.Item(X)) & "', '" &
cboCode.SelectedItem.ToString & "')"
sqlInsertRow2.ExecuteNonQuery()
X = X + 1
Loop

Details of error:

System.InvalidOperationException was unhandled
Message="Prepare: CommandText property has not been initialized"

Error occurs on line: sqlInsertRow2.ExecuteNonQuery()

Please help me fix this.

Thanks

:L

DOH...nevermind I got it. strsqlSPEC and sqlInsertRow2 does not compute

:L
 
Back
Top