deleting a record from sql db - help!

tito_puente41

Member
Joined
Aug 18, 2005
Messages
9
Programming Experience
Beginner
Hi all,

i've been lurking these forums for some time for reference and you guys are great... i'm wondering if you could help with something that should be very simple but i can't get to work, and i've been at it for a few days now...

basically i have a USERS table in a sql db, in it are

userID (unique int identifier, primary key)
usr_name
usr_pass
usr_access

i've been trying to set up an even where a user can delete a record from the db...the code i have is very simple and straight forward and works in one case, but not the other, i'll comment out the code where the problem is occuring...

' Open a database connection.
Dim conn AsString = "server=xxxx; database=xxx;" + "uid=xxx; pwd=xxx;"
Dim sqlConn AsNew SqlConnection(conn)
sqlConn.Open()

Dim strSelect AsString = "SELECT * FROM USERS"
Dim dataAdapter1 As SqlDataAdapter = New SqlDataAdapter(strSelect, sqlConn)
Dim autogen AsNew SqlCommandBuilder(dataAdapter1)

' load a data set.
Dim data_set As DataSet = New DataSet
dataAdapter1.Fill(data_set, "USERS")

' reference to the USERS data_table.
Dim data_table As DataTable = data_set.Tables("USERS")

' delete one of the records. here is where the problem is occuring.
Dim row As DataRow
row = data_table.Select("userID = userID_num")(0)
row.Delete()

' update the db.
dataAdapter1.Update(data_set, "USERS")
sqlConn.Close()




assume that userID_num is an integer and there is code that i left out that gets the correct interger from the db (lets say that number is 4)...

if i say row = data_table.Select("userID = '4'")(0) it will successfully delete row where userID = 4, but whenever i try to get it to userID = userID_num, it always crashes, and the error message is:
Exception Details: System.Data.EvaluateException: Cannot perform '=' operation on System.Int32 and System.String.

what am i doing wrong?!
 
Back
Top