Hi,
Can anyone tell me why datareader is no reading user_id from this code?
I debugged and the user_id_select remains 0 and I am getting no errors.
Protected Sub btnAddUser_Click(sender As Object, e As EventArgs) Handles btnAddUser.Click
Dim conn As New SqlConnection("Data Source=BRIAN-PC\SQLEXPRESS;Initial Catalog=master_db;Integrated Security=True")
Dim searchComm As String = "SELECT user_id FROM users WHERE username=@username"
Dim user_id_select As New Integer
Dim searchSQL As New SqlCommand
conn.Open()
searchSQL = New SqlCommand(searchComm, conn)
searchSQL.Parameters.AddWithValue("@username", txtUserSearch.Text.ToString)
Dim datareader As SqlDataReader = searchSQL.ExecuteReader()
datareader.Read()
While datareader.Read
user_id_select = datareader("user_id")
End While
datareader.Close()
conn.Close()
Dim addComm As String = "INSERT user_id, project_id INTO user_project VALUES (@UserID,@ProjectID)"
Dim addSQL As New SqlCommand
conn.Open()
addSQL = New SqlCommand(addComm, conn)
addSQL.Parameters.AddWithValue("@UserID", Convert.ToInt32(user_id_select))
addSQL.Parameters.AddWithValue("@ProjectID", Convert.ToInt32(Session("project_id")))
Dim datareader2 As SqlDataReader = searchSQL.ExecuteReader()
datareader.Close()
conn.Close()
End Sub