Jump to content

VB.NET SqlDataReader returns wrong values


Recommended Posts

Hey there, I've already spent one day on this problem and still don't know what's wrong. I have a stored procedure giving me some project details. I want to save them into a list. So I created a project class.Using the SqlDataReader, I instantiate the project and put them in the list. Everything works fine, except one datafield. The values are always 0. But if I check the SQL, I'm getting the correct values. I really don't know, why this is happening.

Dim cmd As New SqlCommandcmd.CommandText = "sao.GetProjects"cmd.CommandType = CommandType.StoredProcedurecmd.Connection = New SqlConnection(GetConnectionString)Using cmd.Connection	Using cmd		Dim projects As New List(Of clsProject)		cmd.Connection.Open()		Dim reader As SqlDataReader = cmd.ExecuteReader		While reader.Read			Dim project As New clsProjekt 			'This is the field		    project.employeeNo = reader("employeeNo") 			'Always get Empty			If project.employeeNo = 0 Then				Debug.Print("Empty")			Else				Debug.Print(project.employeeNo)			End If			project.orderNo = reader("OrderNo")			project.description = reader("Description")			project.customer = reader("Customer")			projects.Add(project)		End While	End UsingEnd Using

Thanks for helping

Edited by swine
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...