stored procedure results

  • Thread starter Thread starter jaYPee
  • Start date Start date
J

jaYPee

I have downloaded some source code but I want this to convert the
results into datagrid.

dr = cmd.ExecuteReader()

'****************************************
' SHOW THE RESULTS
'****************************************

sResults = "CustomerID" + vbTab + "ContactName" + vbTab +
vbTab + "CompanyName" + vbCrLf + vbCrLf

While dr.Read()

sResults = sResults + dr.Item("CustomerID") + vbTab +
vbTab
sResults = sResults + dr.Item("ContactName") + vbTab +
vbTab
sResults = sResults + dr.Item("CompanyName") + vbCrLf

End While

dr.Close()

Return sResults

Anyone know how can I put the results into datagrid?

thanks in advance.
 
What you are doing will be problematical at best. First there is the
issue that each sResults statement is overwriting the previous contents.
Now if you want to display things in a datagrid, you could first
rethink the use of a datareader and fill a dataset instead. The
datareader is a one way optimized for reading object so you won't be
able to directly bind it to a datagrid, however if you retrieve your
results to a data grid you can bind it. Finally if you are stuck on
using a datareader then I'd recommend checking out this article showing
how to convert a datareader to a dataset:

http://authors.aspalliance.com/stevesmith/articles/convertReadertoSet.asp

If you follow the article you should be able to bind the resulting
dataset (or more specifically the created table) to the datagrid (from
you method you'd want to return the dataset). Oh, you didn't mention
what type of app you need this for, but it should work equally well for
ASP.Net and winforms. Hope this helps.

Have A Better One!

John M Deal, MCP
Necessity Software
 
Thank you for the fast reply. However I can't use data reader since
the datagrid datasource has already been set. What I need only is to
dump the result into the datagrid.

thanks.
 
I'm not sure I'll be able to help you with this, but I think for anyone
to give it a shot you're going to have to provide more detail on what
you are trying to do.

First, what kind of application are you trying to build? The answers you
get will be different depending on whether or not it is ASP.Net or
Windows Forms.

Second, what is the full scenario. You've now mentioned that you aren't
just trying to get results into a datagrid, but into a data grid whose
datasource has already been set.

Am I correct in this being your scenario? You have a form that has a
datagrid on it that is being filled from an existing dataset. You now
need to query a database to get additional data, the results of which
you somehow want to add to the existing datagrid without replacing the
data that was already there.

If this scenario is correct you need to provide one more piece of
information... where do you expect to put the results of the stored
procedure? Do you want them in the footer of the grid? Do you want to
add a column to the grid to hold the results? Will there be more than
one set of results (i.e. the new stored procedure returns one result for
each row in the original grid data)?

Finally you need to explain what you were attempting in the code sample
that you provided. Does the stored procedure return multiple results
(related to the last question after the scenario above)?

Again I don't know if I'll be able to help you on this but without more
information to work with I'm tapped out of ideas. If you provide this
information you will be more likely to get some help with this.

All that said, please forgive the lengthy email if you've already gotten
help on this from the other group that you posted it to.

Have A Better One!

John M Deal, MCP
Necessity Software
 
Thank you very much for the time. I have already solve some of my
problem. My problem now is on how can I solve the problem when adding
a new record to my table.

This is my source code that works perfectly if I set the table to
"SchYrSemCourseJoin"

Dim dr As DataRow =
DsStudentCourse1.Tables("SchYrSemCourseJoin").NewRow()
dr("CourseID") = intcourse + 1

DsStudentCourse1.Tables("SchYrSemCourseJoin").Rows.Add(dr)

This code works perfectly if the datamember of my datagrid is set to
"SchYrSemCourseJoin". However because I am using a parent/child form
so the actual datamember of my datagrid is
"Students.StudentsSchYrSem.SchYrSemSchYrSemCourseJoin" and the
datasource is "DsStudentCourse1"

By the way I'm using windows form.
 
Back
Top