Hi, can someone help me ? how can i show the result of my SQL statement in a textbox ? Thanks
Showing the result of SQL statement in textbox
Page 1 of 17 Replies - 423 Views - Last Post: 05 October 2012 - 07:16 AM
Replies To: Showing the result of SQL statement in textbox
#2
Re: Showing the result of SQL statement in textbox
Posted 05 October 2012 - 04:51 AM
You display String in TextBox with: myTextBoxName.Text = stringResultOfSQLStatement
#3
Re: Showing the result of SQL statement in textbox
Posted 05 October 2012 - 04:55 AM
Public Function getLastCustomerID() As DataTable
sql = "SELECT TOP 1 CustomerID From tblCustomer ORDER BY CustomerID DESC"
Return da.getDataTable(sql)
End Function
I tried this one, but noting happened "txtCustomerIDOrder.Text = cDA.getLastCustomerID.ToString"
sql = "SELECT TOP 1 CustomerID From tblCustomer ORDER BY CustomerID DESC"
Return da.getDataTable(sql)
End Function
I tried this one, but noting happened "txtCustomerIDOrder.Text = cDA.getLastCustomerID.ToString"
#4
Re: Showing the result of SQL statement in textbox
Posted 05 October 2012 - 05:18 AM
Your getLastCustomerID() function returns result as DataTable type. If your sql query is successful, than you'll get result something like: "System.Data.DataTable". Place a breakpoint to return line of code, and hover over it's members, to see if you actually get something back from database. You can do the same to your txtCustomer.... line of code, and see if getLastCustomerID is Nothing. In that case, your sql isn't working as it should.
#5
Re: Showing the result of SQL statement in textbox
Posted 05 October 2012 - 05:35 AM
If your function returns a datatable then you cannot just call .ToString() on it. you have to dig down and grab the exact column out that you want to work with.
ex:
Now with that the above code is extremely unsafe because if dataTable is null, it won't have any rows to look at and will throw an error. Look over the MSDN Documentation for DataTable for more information
ex:
dataTable.Rows(0)("CustomerID").ToString()
Now with that the above code is extremely unsafe because if dataTable is null, it won't have any rows to look at and will throw an error. Look over the MSDN Documentation for DataTable for more information
#6
Re: Showing the result of SQL statement in textbox
Posted 05 October 2012 - 06:17 AM
my SQL statement was successful and when I try this one
DataGridView.DataSource = cDA.getLastCustomerID
It will show the result that I want, but I want to show it on textbox, not in datagridview. what code should I do ?
DataGridView.DataSource = cDA.getLastCustomerID
It will show the result that I want, but I want to show it on textbox, not in datagridview. what code should I do ?
#7
Re: Showing the result of SQL statement in textbox
Posted 05 October 2012 - 06:27 AM
Because the datagridview can handle a datatable as a datasource regardless if it's multiple rows and columns or just a single row and column.
Did you try rgfirefly24's suggestion?
Also, you don't need an order by clause if you are returning 1 row. Just an observation.
Did you try rgfirefly24's suggestion?
Also, you don't need an order by clause if you are returning 1 row. Just an observation.
This post has been edited by CharlieMay: 05 October 2012 - 06:29 AM
#8
Re: Showing the result of SQL statement in textbox
Posted 05 October 2012 - 07:16 AM
Thank you rgfirefly24 , problem solved !
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote






|