Data Access Question  
Author Message
Tryin2Bgood





PostPosted: Visual Basic Language, Data Access Question Top

I have two forms a login form and a information form....How i have it now u use your firstname as username and lastname as password...Then I want Form2 to take the firstname and the lastname u use to login and run that cmd and send that information to those txtcontrols....When i hardcode some strings and assign those to the where the login txtcontrols go it works from but when i have login.TextBox1.Text it does nothing....any help on this

Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Dim login As Form1 = New Form1()

Dim str As String = System.Configuration.ConfigurationManager.AppSettings("conn")

Dim Sqlconnect As SqlConnection = New SqlConnection(str)

Dim cmd As String = "Select * From Employees Where FirstName = '" & login.TextBox1.Text & "' And LastName = '" & login.TextBox2.Text & "'"

Dim sqlcmd As SqlCommand = New SqlCommand(cmd, Sqlconnect)

Dim dr As SqlDataReader

Dim fname As String = ""

Dim lname As String = ""

Dim fullname As String = ""

Dim position As String = ""

Dim notes As String = ""

Dim address As String = ""

Dim city As String = ""

Dim phonenumber As String = ""

Sqlconnect.Open()

dr = sqlcmd.ExecuteReader()

While dr.Read

fname = dr.Item("FirstName").ToString()

lname = dr.Item("LastName").ToString()

position = dr.Item("Title").ToString()

notes = dr.Item("Notes").ToString()

address = dr.Item("Address").ToString()

city = dr.Item("City").ToString()

phonenumber = dr.Item("HomePhone").ToString()

fullname = fname + " " + lname

Me.txtemployee.Text = fullname

Me.txtaddress.Text = address

Me.txtposition.Text = position

Me.txtphone.Text = phonenumber

Me.txtcity.Text = city

Me.txtnotes.Text = notes

End While

End Sub




Visual Basic4  
 
 
scottwis_MS





PostPosted: Visual Basic Language, Data Access Question Top

In your code you are creating a new instance of Form1 and storing it in the variable login.

This instance of the form should have empty text box values, which is why you are seing the behavior you are.

I assume that you want the behavior of having form2 load, show form 1, wait untill form1 is closed, and then run your query.

To do this you need to call the "ShowDialog()" method on "login" before you run the query (login.ShowDialog())

-Scott

 
 
Tryin2Bgood





PostPosted: Visual Basic Language, Data Access Question Top

How should I add the ShowDialog method it just seems to create a new login form and thats all, not changing the results....Where do i place that within the code to keep the values of what i enter in the textbox

Dim login As Form1 = New Form1()

Dim str As String = System.Configuration.ConfigurationManager.AppSettings("conn")

Dim Sqlconnect As SqlConnection = New SqlConnection(str)

login.ShowDialog()

Dim cmd As String = "Select * From Employees Where FirstName = '" + login.TextBox1.Text + "' And LastName = '" + login.TextBox2.Text + "'"

Dim sqlcmd As SqlCommand = New SqlCommand(cmd, Sqlconnect)

Dim dr As SqlDataReader

Dim fname As String = ""

Dim lname As String = ""

Dim fullname As String = ""

Dim position As String = ""

Dim notes As String = ""

Dim address As String = ""

Dim city As String = ""

Dim phonenumber As String = ""

Sqlconnect.Open()

dr = sqlcmd.ExecuteReader()

While dr.Read

fname = dr.Item("FirstName").ToString()

lname = dr.Item("LastName").ToString()

position = dr.Item("Title").ToString()

notes = dr.Item("Notes").ToString()

address = dr.Item("Address").ToString()

city = dr.Item("City").ToString()

phonenumber = dr.Item("HomePhone").ToString()

fullname = fname + " " + lname

Me.txtemployee.Text = fullname

Me.txtaddress.Text = address

Me.txtposition.Text = position

Me.txtphone.Text = phonenumber

Me.txtcity.Text = city

Me.txtnotes.Text = notes

End While

End Sub



 
 
scottwis_MS





PostPosted: Visual Basic Language, Data Access Question Top

You would put it right after dim login = new form1()

login.ShowDialog()


 
 
Tryin2Bgood





PostPosted: Visual Basic Language, Data Access Question Top

Acutually what i did was Dim login As Form1 = Form1 and that kept the current state of my current form and brought the string values from my text to my query...Thanks everyone for the HELP!!!