473,943 Members | 19,282 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Converting each datagrid line into a string in vb

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.Item s.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
Nov 20 '05 #1
6 4487
"Eric Broers" <er*********@ho tmail.com> 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.Item s.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

Nov 20 '05 #2
All options are open... How do I read from the bound datasource?
"Armin Zingler" <az*******@free net.de> wrote in message
news:OH******** ******@tk2msftn gp13.phx.gbl...
"Eric Broers" <er*********@ho tmail.com> 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.Item s.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

Nov 20 '05 #3
"Eric Broers" <er*********@ho tmail.com> 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

Nov 20 '05 #4
Cor
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).r ows.count - 1)
for i = 0 to ds.tables(0).ro ws.count - 1
mystring(i) = ds.tables(0).ro ws(i).item(0).t ostring
for y = 1 to 3
mystring(i) = mystring & " " & ds.tables(0).ro ws(i).item(y).t ostring
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

Nov 20 '05 #5
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.Data Source = cart.GetItems(c artId)
MyDataGrid.Data Bind()
....
procs.vb:
Public Function GetItems(ByVal cartID As String) As SqlDataReader

' Create Instance of Connection and Command Object
Dim myConnection As SqlConnection = New
SqlConnection(C onfigurationSet tings.AppSettin gs("ConnectionS tring"))
Dim myCommand As SqlCommand = New SqlCommand("Sho ppingCartList",
myConnection)

' Mark the Command as a SPROC
myCommand.Comma ndType = CommandType.Sto redProcedure

' Add Parameters to SPROC
Dim parameterCartID As SqlParameter = New
SqlParameter("@ CartID", SqlDbType.NVarC har, 50)
parameterCartID .Value = cartID
myCommand.Param eters.Add(param eterCartID)

' Execute the command
myConnection.Op en()
Dim result As SqlDataReader =
myCommand.Execu teReader(Comman dBehavior.Close Connection)

' Return the datareader result
Return result

End Function


"Cor" <no*@non.com> wrote in message
news:eL******** ******@TK2MSFTN GP12.phx.gbl...
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).r ows.count - 1)
for i = 0 to ds.tables(0).ro ws.count - 1
mystring(i) = ds.tables(0).ro ws(i).item(0).t ostring
for y = 1 to 3
mystring(i) = mystring & " " & ds.tables(0).ro ws(i).item(y).t ostring
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


Nov 20 '05 #6
Cor
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??

Nov 20 '05 #7

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

Similar topics

18
7978
by: Marcio Kleemann | last post by:
I need to force the first letter of each word in a line of text to uppercase. The text comes from a TextBox control in a Web Form. I'm new to ..NET and am having a problem. Since I can't modify the string directly, I convert the string to a char using .ToCharArray() and set the first letter of each word to uppercase. The problem then is I can't figure out how to convert the char array back to a string. Whether I use .ToString() from the...
8
3692
by: Marius Cabas | last post by:
Hi, I'm a beginner so don't shoot ;) I'm reading a wave file into a byte and I'm trying to convert the result to String but the converted string is altered, so if I'm generating a new wave file from that string, the continment is altered from it's original state. Below is a code snipped I'm using: // Here I read the wave file and I convert the result to a string byte b = new byte; FileStream fs = File.OpenRead("test.wav"); int size =...
10
15565
by: Kim Hellan | last post by:
I have a simple string in the format "DD-MM-YY hh:mm:ss", that I need to convert to a DateTime value. I know this is a standard problem, but please don't just link to all the MSDN pages regarding Parse() and ParseExact(). I've been there and read all the information about using IFormatProviders, DateTimeStyles, CultureInfo....... Bottom line is that I can't get it working, so could someone please just post 5-10 lines of working code...
5
1875
by: Andrew Banks | last post by:
Can anyone see aproblem with this line of code string rolelistarray = rolelist.ToArray(GetType(System.String)); I'm getting a problem with the GetType(System.String) section
3
2538
by: Lerp | last post by:
Hi all, What's the syntax for creating a row out of the current item in a datagrid? Something like this ? Dim myRow as DataRow = mydataGrid.DataKeys(e.item.itemindex)
8
4217
by: moondaddy | last post by:
I need to convert a byte array to a string and pass it as a parameter in a URL and then convert it back to the original byte array. However, its getting scrambled in the conversion. In short, here's the code: ====================================== Dim textConverter As New ASCIIEncoding Dim sParam As String = "This is my cool param" Dim bytParam() As Byte 'load the byte array here...
3
28536
by: Wallace | last post by:
Hai, Can anyone tell how to convert an object into string? Please help me.... urgent.. Thanx in advance...
12
13413
by: Samir | last post by:
Hi Everyone, I am relatively new to Python so please forgive me for what seems like a basic question. Assume that I have a list, a, composed of nested lists with string representations of integers, such that a = , , , ]
0
1442
by: dougancil | last post by:
I have the following code: Imports System.Data.SqlClient Public Class Main Protected WithEvents DataGridView1 As DataGridView Dim instForm2 As New Exceptions Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles startpayrollButton.Click Dim ssql As String = "select MAX(payrolldate) AS , " & _ "dateadd(s, 518399, max(payrolldate)) AS " & _
0
9970
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11133
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
11303
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10666
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
8228
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7393
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
6090
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4913
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4515
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.