PC Review


Reply
Thread Tools Rate Thread

Converting each datagrid line into a string in vb

 
 
Eric Broers
Guest
Posts: n/a
 
      14th Dec 2003
LS,

Assume I have a datagrid, which is filled by an SQL statement (Select * from
Customer). The Customers table contains 4 columns and 10 rows.

Now, I want to fill 10 strings with the datagrid rows. So, sting1 should
become the first database row, string2 the 2nd, etc, etc

So, I tried this:

For i = 0 To MyDataGrid.Items.Count - 1
string1 = ????????????????????????
Next

How do I read the datagrid and put it into a string? I hope someone can help
me out with this one.

Many thanks!!

Eric


 
Reply With Quote
 
 
 
 
Armin Zingler
Guest
Posts: n/a
 
      14th Dec 2003
"Eric Broers" <(E-Mail Removed)> schrieb
>
> Assume I have a datagrid, which is filled by an SQL statement (Select
> * from Customer). The Customers table contains 4 columns and 10
> rows.
>
> Now, I want to fill 10 strings with the datagrid rows. So, sting1
> should become the first database row, string2 the 2nd, etc, etc
>
> So, I tried this:
>
> For i = 0 To MyDataGrid.Items.Count - 1
> string1 = ????????????????????????
> Next
>
> How do I read the datagrid and put it into a string? I hope someone
> can help me out with this one.


Why not read from the bound datasource?


--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

 
Reply With Quote
 
Eric Broers
Guest
Posts: n/a
 
      14th Dec 2003
All options are open... How do I read from the bound datasource?


"Armin Zingler" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> "Eric Broers" <(E-Mail Removed)> schrieb
> >
> > Assume I have a datagrid, which is filled by an SQL statement (Select
> > * from Customer). The Customers table contains 4 columns and 10
> > rows.
> >
> > Now, I want to fill 10 strings with the datagrid rows. So, sting1
> > should become the first database row, string2 the 2nd, etc, etc
> >
> > So, I tried this:
> >
> > For i = 0 To MyDataGrid.Items.Count - 1
> > string1 = ????????????????????????
> > Next
> >
> > How do I read the datagrid and put it into a string? I hope someone
> > can help me out with this one.

>
> Why not read from the bound datasource?
>
>
> --
> Armin
>
> http://www.plig.net/nnq/nquote.html
> http://www.netmeister.org/news/learn2quote.html
>



 
Reply With Quote
 
Armin Zingler
Guest
Posts: n/a
 
      14th Dec 2003
"Eric Broers" <(E-Mail Removed)> schrieb
> All options are open... How do I read from the bound datasource?


Did you bind the datagrid to a dataset or a datatable? If you did, you can
access the bound datatable. Have a look at the documentation of the
DataTable class.

See also the ADO.NET chapters (these and others):
http://msdn.microsoft.com/library/en...datatables.asp
http://msdn.microsoft.com/library/en...tingDataVB.asp

--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

 
Reply With Quote
 
Cor
Guest
Posts: n/a
 
      15th Dec 2003
Hi Eric,

The Datagrid is something that mostly shows data. That is always from
something that is inheritted from the iList and mostly a datatable. (Maybe
using a dataview).

Dont try to grab the data from the datagrid, take it from the datatable.
Trough that you can easily itterate by (and I show you an example with a
dataset wich have one table)

\\\roughly written watch typoes
dim i, y as integer
dim mystring as string (ds.tables(0).rows.count - 1)
for i = 0 to ds.tables(0).rows.count - 1
mystring(i) = ds.tables(0).rows(i).item(0).tostring
for y = 1 to 3
mystring(i) = mystring & " " & ds.tables(0).rows(i).item(y).tostring
next y
next
////

I hope this helps?

Cor

>
> Assume I have a datagrid, which is filled by an SQL statement (Select *

from
> Customer). The Customers table contains 4 columns and 10 rows.
>
> Now, I want to fill 10 strings with the datagrid rows. So, sting1 should
> become the first database row, string2 the 2nd, etc, etc
>



 
Reply With Quote
 
Eric Broers
Guest
Posts: n/a
 
      17th Dec 2003
Hi Cor,

ok, I get it. But I am obly able to fill a datagrid by the following
statements (see the bottom of this message).

So now my question is, how do I fill the dataset by calling a stored
procedure??

Many thanks!

Eric



shop.aspx:
Private Sub Page_Load(.....)
MyDataGrid.DataSource = cart.GetItems(cartId)
MyDataGrid.DataBind()
....


procs.vb:
Public Function GetItems(ByVal cartID As String) As SqlDataReader

' Create Instance of Connection and Command Object
Dim myConnection As SqlConnection = New
SqlConnection(ConfigurationSettings.AppSettings("ConnectionString"))
Dim myCommand As SqlCommand = New SqlCommand("ShoppingCartList",
myConnection)

' Mark the Command as a SPROC
myCommand.CommandType = CommandType.StoredProcedure

' Add Parameters to SPROC
Dim parameterCartID As SqlParameter = New
SqlParameter("@CartID", SqlDbType.NVarChar, 50)
parameterCartID.Value = cartID
myCommand.Parameters.Add(parameterCartID)

' Execute the command
myConnection.Open()
Dim result As SqlDataReader =
myCommand.ExecuteReader(CommandBehavior.CloseConnection)

' Return the datareader result
Return result

End Function




"Cor" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi Eric,
>
> The Datagrid is something that mostly shows data. That is always from
> something that is inheritted from the iList and mostly a datatable. (Maybe
> using a dataview).
>
> Dont try to grab the data from the datagrid, take it from the datatable.
> Trough that you can easily itterate by (and I show you an example with a
> dataset wich have one table)
>
> \\\roughly written watch typoes
> dim i, y as integer
> dim mystring as string (ds.tables(0).rows.count - 1)
> for i = 0 to ds.tables(0).rows.count - 1
> mystring(i) = ds.tables(0).rows(i).item(0).tostring
> for y = 1 to 3
> mystring(i) = mystring & " " & ds.tables(0).rows(i).item(y).tostring
> next y
> next
> ////
>
> I hope this helps?
>
> Cor
>
> >
> > Assume I have a datagrid, which is filled by an SQL statement (Select *

> from
> > Customer). The Customers table contains 4 columns and 10 rows.
> >
> > Now, I want to fill 10 strings with the datagrid rows. So, sting1 should
> > become the first database row, string2 the 2nd, etc, etc
> >

>
>



 
Reply With Quote
 
Cor
Guest
Posts: n/a
 
      18th Dec 2003
Hi Eric,

I use for this a dataset instead of the datareader, now you have to make the
underlaying tables, while the dataset makes that direct.

You need for that also a sqlDataadapter that uses the command.

I hope this helps?

Cor

>
> ok, I get it. But I am obly able to fill a datagrid by the following
> statements (see the bottom of this message).
>
> So now my question is, how do I fill the dataset by calling a stored
> procedure??
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
incorrect result when converting from basic string to System::String Vivienne Microsoft C# .NET 1 20th Aug 2007 07:00 AM
Re: Converting a string to a string that contains the ASCII values of each letter in the origional string Jay B. Harlow [MVP - Outlook] Microsoft C# .NET 7 1st Aug 2003 06:03 PM
Re: Converting a string to a string that contains the ASCII values of each letter in the origional string Mikael Jansson Microsoft C# .NET 0 31st Jul 2003 08:42 PM
Re: Converting a string to a string that contains the ASCII values of each letter in the origional string Jon Skeet Microsoft C# .NET 0 31st Jul 2003 08:38 PM
Re: Converting a string to a string that contains the ASCII values of each letter in the origional string Frank Oquendo Microsoft C# .NET 0 31st Jul 2003 08:36 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:36 AM.