473,386 Members | 1,757 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,386 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 1999
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.