|
-
Feb 4th, 2008, 12:23 AM
#1
Thread Starter
Frenzied Member
[2008] What is wrong with this code? (SQL Command)
vb.net Code:
Dim sqlCon As New SqlConnection("Data Source=ICYCULYR\SQLEXPRESS;Initial Catalog=test_kcDB;Integrated Security=True;Pooling=False")
sqlCon.Open()
Dim sqlCommand As New SqlCommand()
sqlCommand.Connection = sqlCon
Dim returnValue As Object = "Nothing"
Select Case whichPreference
Case PreferencesEnum.dblClickMenu
sqlCommand.CommandText = ("SELECT preferences_value FROM dataTable")
Dim sqlReader As SqlDataReader = sqlCommand.ExecuteReader()
Dim tmpInt As Integer = 0
While sqlReader.Read()
If tmpInt = whichPreference Then
returnValue = sqlReader.GetValue(tmpInt)
Exit While
End If
tmpInt += 1
End While
End Select
sqlCon.Close()
the problem line is 'returnValue = sqlReader.GetValue(tmpInt)',
my value is DBNULL, but should return the first value of my column, which would be 'true'.
I assume sqlReader is reading the rows from my column 'preferences_value', so I don't see why it isn't working?
sqlReader.GetValue(tmpInt) (tmpInt being 0, as whichPreference is 0)
it should return the first row.
If anyone could help me with this?
Thanks
-
Feb 4th, 2008, 05:27 AM
#2
Re: [2008] What is wrong with this code? (SQL Command)
I am unsure what you are trying to achieve with the tmpInt variable.
The parameter for SqlDataReader.GetValue is the zero-based column index (as you can learn from MSDN). This will always be zero in your example since you're only selecting one column.
-
Feb 5th, 2008, 05:53 PM
#3
Thread Starter
Frenzied Member
Re: [2008] What is wrong with this code? (SQL Command)
I see, thanks, I have several preferences stored in one column, and tmpInt tells me which one.
Thanks
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|