pOopOo

Hi..ihave this code and im having ahard time figuring it how to display my query in a textbox..im using MS ACCESS as database and using vb2005

theCode:
Private Sub AddButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AddButton.Click
Dim NameText As String
Dim AreaText As String
Dim conn As New OleDbConnection
NameText = NameBox.Text
AreaText = AreaBox.Text


conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\xample\xample\bin\Debug\db.mdb;"

Dim adapter As OleDbDataAdapter = New OleDbDataAdapter()
Dim command As OleDbCommand

command = New OleDbCommand("SELECT * FROM Customers " & _
"WHERE Names = popo", conn)

command.Parameters.Add("Names", OleDbType.VarChar, 15)
command.Parameters.Add("Area", OleDbType.VarChar, 15)

adapter.SelectCommand = command
End Sub

what should i add to put the "Names" and "Area" in a TextBox


Re: .NET Framework Data Access and Storage Displaying a Query in a TextBox..help

BonnieB

You need to Fill a DataSet and then DataBind your TextBoxes to that DataSet, something like this (not 100% sure of VB syntax, so I'm winging it):

¡®First you need a DataSet

Dim ds As New DataSet

Then, in your button click, first Fill the DataSet and then DataBind your TextBoxes:

adapter.SelectCommand = command

adapter.Fill(ds)

¡®Now do the DataBinding

NameBox.DataBind.Add(¡°Text¡±, ds.Tables(0), ¡°NameColumnName¡±)

AreaBox.DataBind.Add(¡°Text¡±, ds.Tables(0), ¡°AreaColumnName¡±)






Re: .NET Framework Data Access and Storage Displaying a Query in a TextBox..help

pOopOo

ahh i see....i'll try it out...tnx...what is the syntax when i use as a variable in a select command like

this:
select [variable] from table where name = [variable]




Re: .NET Framework Data Access and Storage Displaying a Query in a TextBox..help

BonnieB

You know, I may have misunderstood what you were asking initially. Did you want to know how to set the parameters Because I see that you tried to add them, but then you never used them. So, you had this:

command = New OleDbCommand("SELECT * FROM Customers " & _
"WHERE Names = popo", conn)

command.Parameters.Add("Names", OleDbType.VarChar, 15)
command.Parameters.Add("Area", OleDbType.VarChar, 15)

Were you initally asking about this kind of syntax

command = New OleDbCommand("SELECT * FROM Customers " & _
"WHERE Names = AND Area = ", conn)

command.Parameters.Add("Names", OleDbType.VarChar, 15, NameBox.Text)
command.Parameters.Add("Area", OleDbType.VarChar, 15, AreaBox.Text)






Re: .NET Framework Data Access and Storage Displaying a Query in a TextBox..help

pOopOo

that "popo" is suppose to be a variable...now i know...so no need to put a variable in command

ryt because of

command.Parameters.Add("Names", OleDbType.VarChar, 15, NameBox.Text)
command.Parameters.Add("Area", OleDbType.VarChar, 15, AreaBox.Text)

how should i output the query to a textbox




Re: .NET Framework Data Access and Storage Displaying a Query in a TextBox..help

BonnieB

The DataBinding syntax that I used in my first post.




Re: .NET Framework Data Access and Storage Displaying a Query in a TextBox..help

pOopOo

ok..how to i put the result to a textbox




Re: .NET Framework Data Access and Storage Displaying a Query in a TextBox..help

BonnieB

That's the question I just answered ... how do you put the results to a textbox ... use the DataBinding methodology that I posted earlier.