• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 139
  • Last Modified:

Sql - fill textboxes

I want to use retreive a record by providing a requested number in   txtTranNumber.text  and then the selected row is to be filled in in txtAddress and txtCityState. How can I accomplish this?  This is the code I have come up so far.


.....

Try





Dim Conn As SqlConnection = New SqlConnection("workstation id=""just a test"";packet size=1000;user id=userx;data source=just a test" & _

"ist security info=True;initial catalog=Results;password=just a test")





Dim StrCommand As String = " Select address, citystate from results where transno = " ' " & Me.txtTrannumber.Text & " ' "



Dim MyCommand As New SqlCommand(StrCommand, Conn)



Conn.Open()



MyCommand.ExecuteNonQuery()



Conn.Close()



Catch ex As SqlException



MsgBox(ex.ToString)





End Try
0
VBdotnet2005
Asked:
VBdotnet2005
1 Solution
 
Carl TawnSystems and Integration DeveloperCommented:
VBdotnet2005,

This is a duplicate of your question in the ASP.Net topic area. Should request to have one of these questions deleted or changed to point to the other.
0
 
YZlatCommented:
replace this line

MyCommand.ExecuteNonQuery()

with

Dim dr as SqlDataReader
dr=MyCommand.ExecuteReader()

While dr.Read
txtAddress.Text=dr("address")
txtCityState.Text=dr("citistate")
End while

MyCommand.ExecuteNonQuery() would execute INSERT, UPDATE, or DELETE queries and not used with SELECT
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now