Displaying data from database in textboxes.

S

Schapopa

Hello,

I have form where I want to display data from one record. So I created
stored procedure with parameter and I populated some dropdown boxes
with data, and now I would like to display that record in the
textboxes and combo boxes.
So I have data conection, data adapter and query with parameter.
How do I bind this to textboxes and dropdown boxes.
textbox.text = ?? I guess what I cannot find is how to point to
specific field in the dataset.
Below is piece of code that I am using for dataadapter and dataset:

conn.Open()

Dim daCategory As New SqlDataAdapter("sp_task", conn)
daCategory.SelectCommand.CommandType =
CommandType.StoredProcedure

Dim IDtask As New SqlParameter("@IDTask",
System.Data.SqlDbType.NVarChar)
IDtask.Direction = ParameterDirection.Input
IDtask.Value = Request.QueryString("IDTAsk")
daCategory.SelectCommand.Parameters.Add(IDtask)

Dim dsZadanie As New DataSet
daCategory.Fill(dsTask, "Task")

Thank's
Arek
 
G

GrantMagic

If you are only returning one value from a query, its best to use the
DataReader.
So, say you stored proc returns a single valu, you can use the datareader as
follows:

Dim ObjCmd as New OleDbCommand("sp_task", conn)
ObjCmd.CommandType = CommandType.StoredProcedure
Dim IDtask As New SqlParameter("@IDTask",
System.Data.SqlDbType.NVarChar)
IDtask.Direction = ParameterDirection.Input
IDtask.Value = Request.QueryString("IDTAsk")
ObjCmd.Paramters.Add(IDtask)

conn.Open()
Dim dr as OleDbDataReader = ObjCmd.ExecuteReader()
if dr.Read() then
textbox.text = Convert.ToString(dr[0])
end if
connClose()
 
S

S. Justin Gengo

ExecuteScalar would be even faster.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
GrantMagic said:
If you are only returning one value from a query, its best to use the
DataReader.
So, say you stored proc returns a single valu, you can use the datareader
as follows:

Dim ObjCmd as New OleDbCommand("sp_task", conn)
ObjCmd.CommandType = CommandType.StoredProcedure
Dim IDtask As New SqlParameter("@IDTask",
System.Data.SqlDbType.NVarChar)
IDtask.Direction = ParameterDirection.Input
IDtask.Value = Request.QueryString("IDTAsk")
ObjCmd.Paramters.Add(IDtask)

conn.Open()
Dim dr as OleDbDataReader = ObjCmd.ExecuteReader()
if dr.Read() then
textbox.text = Convert.ToString(dr[0])
end if
connClose()




Schapopa said:
Hello,

I have form where I want to display data from one record. So I created
stored procedure with parameter and I populated some dropdown boxes
with data, and now I would like to display that record in the
textboxes and combo boxes.
So I have data conection, data adapter and query with parameter.
How do I bind this to textboxes and dropdown boxes.
textbox.text = ?? I guess what I cannot find is how to point to
specific field in the dataset.
Below is piece of code that I am using for dataadapter and dataset:

conn.Open()

Dim daCategory As New SqlDataAdapter("sp_task", conn)
daCategory.SelectCommand.CommandType =
CommandType.StoredProcedure

Dim IDtask As New SqlParameter("@IDTask",
System.Data.SqlDbType.NVarChar)
IDtask.Direction = ParameterDirection.Input
IDtask.Value = Request.QueryString("IDTAsk")
daCategory.SelectCommand.Parameters.Add(IDtask)

Dim dsZadanie As New DataSet
daCategory.Fill(dsTask, "Task")

Thank's
Arek
 
A

Arek Lubinski

Thank you for your help,
So I am using datareader and it works very good.
I started to use dataset but really there is no need for that.
Regards
Arek
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top