473,228 Members | 1,902 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,228 software developers and data experts.

Display dataset results in textboxes

Hello -

I have the following stored procedure and code. I want to put the results
in two textboxes. I get to the part where I create the dataset and then I
don't know what to do. I tried using a dataview with no luck.

Stored procedure:
ALTER Proc spFillSbjRply
(
@key int
)
AS
Select
tblLogin.ScreenName, tblPost.Question
from tblPost
inner join tblLogin
ON tblLogin.UserID = tblPost.UserID
Where tblPost.PostID=@key

Click event of a button:
index = dgPost.SelectedIndex
key = dgPost.DataKeys(index)
Dim dsSbjRply as New DataSet
Dim cmdSbjRply as New SqlClient.SqlCommand()
Dim daSbjRply as New SqlClient.SqlDataAdapter()
Dim prmSbjRply as SqlClient.SqlParameter

cmdSbjRply = cnn.CreateCommand
cmdSbjRply.CommandType = CommandType.StoredProcedure
cmdSbjRply.CommandText = "spFillSbjRply"
prmSbjRply = cmdSbjRply.Parameters.Add("@key", SqlDbType.Int, 4)
prmSbjRply.Value = key

daSbjRply.SelectCommand = cmdSbjRply
daSbjRply.Fill(dsSbjRply, "PostQ")

I'M STUCK HERE.

Any help will be immensely appreciated!!

--
Sandy
Nov 19 '05 #1
2 1994
Hi Sandy,

I'm not sure what's inside your dataset, but here's some example code that
might get you unstuck. You need to use a dataview and a rowfilter
expression.

Let us know if it helps?

Ken
Microsoft MVP [ASP.NET]
Toronto

Private Sub Page_Load _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
' From Ken Cox Microsoft MVP [ASP.NET]
If Not IsPostBack Then
' Create a dataset
Dim ds As New DataSet
' Add a table to the dataset
ds.Tables.Add(CreateDataSource())
' Create a filter so that we only get one row
ds.Tables(0).DefaultView.RowFilter = "IntegerValue = 5"
' Pass the dataset plus an expression to DataBinder.Eval
' so that it returns the string called StringValue in
' the default dataview
TextBox1.Text = DataBinder.Eval(ds, _
"Tables(0).DefaultView(0).StringValue")
' Bind everything on the page
Page.DataBind()
End If
End Sub

Private Sub Button1_Click _
(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles Button1.Click
Label1.Text = TextBox1.Text
End Sub

Function CreateDataSource() As DataTable
Dim dt As New DataTable
Dim dr As DataRow
dt.Columns.Add(New DataColumn _
("IntegerValue", GetType(Int32)))
dt.Columns.Add(New DataColumn _
("StringValue", GetType(String)))
dt.Columns.Add(New DataColumn _
("CurrencyValue", GetType(Double)))
dt.Columns.Add(New DataColumn _
("Boolean", GetType(Boolean)))
Dim i As Integer
For i = 0 To 5
dr = dt.NewRow()
dr(0) = i
dr(1) = "Item " + i.ToString()
dr(2) = 1.23 * (i + 1)
dr(3) = (i = 4)
dt.Rows.Add(dr)
Next i
Return dt
End Function

"Sandy" <Sa***@discussions.microsoft.com> wrote in message
news:BF**********************************@microsof t.com...
Hello -

I have the following stored procedure and code. I want to put the results
in two textboxes. I get to the part where I create the dataset and then I
don't know what to do. I tried using a dataview with no luck.

Stored procedure:
ALTER Proc spFillSbjRply
(
@key int
)
AS
Select
tblLogin.ScreenName, tblPost.Question
from tblPost
inner join tblLogin
ON tblLogin.UserID = tblPost.UserID
Where tblPost.PostID=@key

Click event of a button:
index = dgPost.SelectedIndex
key = dgPost.DataKeys(index)
Dim dsSbjRply as New DataSet
Dim cmdSbjRply as New SqlClient.SqlCommand()
Dim daSbjRply as New SqlClient.SqlDataAdapter()
Dim prmSbjRply as SqlClient.SqlParameter

cmdSbjRply = cnn.CreateCommand
cmdSbjRply.CommandType = CommandType.StoredProcedure
cmdSbjRply.CommandText = "spFillSbjRply"
prmSbjRply = cmdSbjRply.Parameters.Add("@key", SqlDbType.Int, 4)
prmSbjRply.Value = key

daSbjRply.SelectCommand = cmdSbjRply
daSbjRply.Fill(dsSbjRply, "PostQ")

I'M STUCK HERE.

Any help will be immensely appreciated!!

--
Sandy

Nov 19 '05 #2
Hi Ken -

Thanks for your reply! Wow -- seems like a lot of code for little 'ol
textboxes.

My stored procedure results, hence my dataset, consist of two items -
ScreenName and Question. The "key" is what filters it into one row. Since I
am already "filtered," how does this part work:

ds.Tables(0).DefaultView.RowFilter = "IntegerValue = 5"

I can get both items to show up in a repeater if I don't use a stored
procedure and just put the Select statement in code (which I DON'T want to
do). Also, I don't want "ScreenName" in the repeater because I want to reuse
it for an insert and I don't know how to get that value out of a repeater . .
.. that's why I'm opting for textboxes now . . . it's easy to get the values
out.

Sorry I wasn't clear -- don't know how clear the above is either . . . Any
ideas of a shorter method? I have a gazillion things going on in this page
and was hoping for simple code for this, if possible. I'm easily confused.

Thanks again, Ken

Sandy

"Ken Cox [Microsoft MVP]" wrote:
Hi Sandy,

I'm not sure what's inside your dataset, but here's some example code that
might get you unstuck. You need to use a dataview and a rowfilter
expression.

Let us know if it helps?

Ken
Microsoft MVP [ASP.NET]
Toronto

Private Sub Page_Load _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
' From Ken Cox Microsoft MVP [ASP.NET]
If Not IsPostBack Then
' Create a dataset
Dim ds As New DataSet
' Add a table to the dataset
ds.Tables.Add(CreateDataSource())
' Create a filter so that we only get one row
ds.Tables(0).DefaultView.RowFilter = "IntegerValue = 5"
' Pass the dataset plus an expression to DataBinder.Eval
' so that it returns the string called StringValue in
' the default dataview
TextBox1.Text = DataBinder.Eval(ds, _
"Tables(0).DefaultView(0).StringValue")
' Bind everything on the page
Page.DataBind()
End If
End Sub

Private Sub Button1_Click _
(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles Button1.Click
Label1.Text = TextBox1.Text
End Sub

Function CreateDataSource() As DataTable
Dim dt As New DataTable
Dim dr As DataRow
dt.Columns.Add(New DataColumn _
("IntegerValue", GetType(Int32)))
dt.Columns.Add(New DataColumn _
("StringValue", GetType(String)))
dt.Columns.Add(New DataColumn _
("CurrencyValue", GetType(Double)))
dt.Columns.Add(New DataColumn _
("Boolean", GetType(Boolean)))
Dim i As Integer
For i = 0 To 5
dr = dt.NewRow()
dr(0) = i
dr(1) = "Item " + i.ToString()
dr(2) = 1.23 * (i + 1)
dr(3) = (i = 4)
dt.Rows.Add(dr)
Next i
Return dt
End Function

"Sandy" <Sa***@discussions.microsoft.com> wrote in message
news:BF**********************************@microsof t.com...
Hello -

I have the following stored procedure and code. I want to put the results
in two textboxes. I get to the part where I create the dataset and then I
don't know what to do. I tried using a dataview with no luck.

Stored procedure:
ALTER Proc spFillSbjRply
(
@key int
)
AS
Select
tblLogin.ScreenName, tblPost.Question
from tblPost
inner join tblLogin
ON tblLogin.UserID = tblPost.UserID
Where tblPost.PostID=@key

Click event of a button:
index = dgPost.SelectedIndex
key = dgPost.DataKeys(index)
Dim dsSbjRply as New DataSet
Dim cmdSbjRply as New SqlClient.SqlCommand()
Dim daSbjRply as New SqlClient.SqlDataAdapter()
Dim prmSbjRply as SqlClient.SqlParameter

cmdSbjRply = cnn.CreateCommand
cmdSbjRply.CommandType = CommandType.StoredProcedure
cmdSbjRply.CommandText = "spFillSbjRply"
prmSbjRply = cmdSbjRply.Parameters.Add("@key", SqlDbType.Int, 4)
prmSbjRply.Value = key

daSbjRply.SelectCommand = cmdSbjRply
daSbjRply.Fill(dsSbjRply, "PostQ")

I'M STUCK HERE.

Any help will be immensely appreciated!!

--
Sandy


Nov 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: olle | last post by:
Hi everyone. Beging a newbee to asp.net and used to work with traditional asp I have one problem working with a datalist. 1/ I make a dataset as as session variable like session("employees") 2/...
3
by: Ed_P. | last post by:
Hello I have a Windows Form that I am trying to use to display data in a DataGrid object from an Access Database. I have created an OleDbCommand Object (with the appropriate Connection string) to...
1
by: MicroMoth | last post by:
I know that this is probably a simple question, but I can't seem to find out how to populate the form fields I have with the results from my stored procedure, which I have stored in a datase. I...
0
by: mkd1919 | last post by:
I have a website that performs a search on an indexing service and returns the results. During the initial load, I get the recordcount through a DS, then bind a DataList using a second DS with...
4
by: Rich | last post by:
Hello, I have successfully created an oledbconnection (oleconn) to an Access mdb file along with an oleaDBdapter (oleda) and a dataset (ds1). If I loop through the dataset For i = 1 to 10...
4
by: Peter Newman | last post by:
i have a dataset and want to step thrpugh each row each time a user clicks a button,
2
by: rn5a | last post by:
The different Validation controls like RequiredFieldValidator, RangeValidator etc. have a property named Display. This property can have 3 values - Dynamic, Static & None. What's the difference...
0
by: Adam Sandler | last post by:
Hello, Prior to posting I looked at http://groups.google.com/group/ microsoft.public.dotnet.framework.aspnet/browse_thread/thread/ d8d5ae243614085e/d4fd6c4a5aa56f75 ...
2
by: J055 | last post by:
Hi I need to search a number of DataTables within a DataSet (with some relationships) and then display the filtered results in a GridView. The Columns that need to be displayed come from 2 of...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.