473,320 Members | 1,804 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,320 software developers and data experts.

Looping through a datagrid

Can anyone give me an example of how I can loop through a datagrid and have
it run a stored procedure each time it loops?
Nov 16 '05 #1
7 4843
Brian,

Why would you loop through a data grid? If anything, I would think that
you want to create a data adapter, and then have it update the underlying
data source based on the changes that have occured.

Also, are you using Windows Forms or ASP.NET?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Brian Conway" <Br**********@qwest.com> wrote in message
news:eI*************@TK2MSFTNGP10.phx.gbl...
Can anyone give me an example of how I can loop through a datagrid and have it run a stored procedure each time it loops?

Nov 16 '05 #2
Well I am not sure that that is the right thing to be doing. This is my
first attempt at creating a working Datagrid and having it update to a
database. What I have right now to pull the data is the following code. I
think though that I saw somewhere that I don't need to open and close the
connections though since the dataadapter is supposed to do this. I have
made some fields in the grid editable and want those changes to hit the
database at the same time with an update button that I have at the bottom of
the grid. From here I have no idea how to get the updates submitted to the
database. This is a webform. I am so lost on this part. Form fields to
the database are easy, but updating from a datagrid I am getting confused.

OleDbConnection conn = new
OleDbConnection(ConfigurationSettings.AppSettings["FleetConnectionString"]);

conn.Open();

OleDbDataAdapter cmd = new OleDbDataAdapter(sqlQuery, conn);

cmd.SelectCommand.Parameters.Add("@cuid", OleDbType.VarChar, 20).Value =
Session["CUID"];

DataSet dsFleet = new DataSet();

cmd.Fill(dsFleet);
DataGrid1.DataSource = dsFleet;

DataGrid1.SelectedIndex = 0;

DataGrid1.DataBind();

conn.Close();

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:uD**************@tk2msftngp13.phx.gbl...
Brian,

Why would you loop through a data grid? If anything, I would think that you want to create a data adapter, and then have it update the underlying
data source based on the changes that have occured.

Also, are you using Windows Forms or ASP.NET?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Brian Conway" <Br**********@qwest.com> wrote in message
news:eI*************@TK2MSFTNGP10.phx.gbl...
Can anyone give me an example of how I can loop through a datagrid and

have
it run a stored procedure each time it loops?


Nov 16 '05 #3
it would probably be better to run through the datasource you have connected
to it.
"Brian Conway" <Br**********@qwest.com> wrote in message
news:eI*************@TK2MSFTNGP10.phx.gbl...
Can anyone give me an example of how I can loop through a datagrid and have it run a stored procedure each time it loops?

Nov 16 '05 #4
How do I do this?
"Greg Young" <gr********@planetbeach.com> wrote in message
news:Ov**************@TK2MSFTNGP10.phx.gbl...
it would probably be better to run through the datasource you have connected to it.
"Brian Conway" <Br**********@qwest.com> wrote in message
news:eI*************@TK2MSFTNGP10.phx.gbl...
Can anyone give me an example of how I can loop through a datagrid and

have
it run a stored procedure each time it loops?


Nov 16 '05 #5
Brian,

The ASP.NET model is different from the Windows Forms model. In the
ASP.NET model, you have to set up event handlers that will perform the
updating of the data when the request is posted back to the server. There
is an example of how to do this in the .NET documentation titled "Updating
Data in a SQL Database", located at (watch for line wrap):

http://msdn.microsoft.com/library/de...qldatabase.asp
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Brian Conway" <Br**********@qwest.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Well I am not sure that that is the right thing to be doing. This is my
first attempt at creating a working Datagrid and having it update to a
database. What I have right now to pull the data is the following code. I think though that I saw somewhere that I don't need to open and close the
connections though since the dataadapter is supposed to do this. I have
made some fields in the grid editable and want those changes to hit the
database at the same time with an update button that I have at the bottom of the grid. From here I have no idea how to get the updates submitted to the database. This is a webform. I am so lost on this part. Form fields to
the database are easy, but updating from a datagrid I am getting confused.

OleDbConnection conn = new
OleDbConnection(ConfigurationSettings.AppSettings["FleetConnectionString"]);
conn.Open();

OleDbDataAdapter cmd = new OleDbDataAdapter(sqlQuery, conn);

cmd.SelectCommand.Parameters.Add("@cuid", OleDbType.VarChar, 20).Value =
Session["CUID"];

DataSet dsFleet = new DataSet();

cmd.Fill(dsFleet);
DataGrid1.DataSource = dsFleet;

DataGrid1.SelectedIndex = 0;

DataGrid1.DataBind();

conn.Close();

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in message news:uD**************@tk2msftngp13.phx.gbl...
Brian,

Why would you loop through a data grid? If anything, I would think

that
you want to create a data adapter, and then have it update the underlying data source based on the changes that have occured.

Also, are you using Windows Forms or ASP.NET?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Brian Conway" <Br**********@qwest.com> wrote in message
news:eI*************@TK2MSFTNGP10.phx.gbl...
Can anyone give me an example of how I can loop through a datagrid and

have
it run a stored procedure each time it loops?



Nov 16 '05 #6
The example that they are showing on the link is for doing invidual row
updates, instead of a mutiple row update though.
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:%2****************@tk2msftngp13.phx.gbl...
Brian,

The ASP.NET model is different from the Windows Forms model. In the
ASP.NET model, you have to set up event handlers that will perform the
updating of the data when the request is posted back to the server. There
is an example of how to do this in the .NET documentation titled "Updating
Data in a SQL Database", located at (watch for line wrap):

http://msdn.microsoft.com/library/de...qldatabase.asp

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Brian Conway" <Br**********@qwest.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Well I am not sure that that is the right thing to be doing. This is my
first attempt at creating a working Datagrid and having it update to a
database. What I have right now to pull the data is the following code. I
think though that I saw somewhere that I don't need to open and close the
connections though since the dataadapter is supposed to do this. I have
made some fields in the grid editable and want those changes to hit the
database at the same time with an update button that I have at the bottom of
the grid. From here I have no idea how to get the updates submitted to

the
database. This is a webform. I am so lost on this part. Form fields

to the database are easy, but updating from a datagrid I am getting confused.
OleDbConnection conn = new

OleDbConnection(ConfigurationSettings.AppSettings["FleetConnectionString"]);

conn.Open();

OleDbDataAdapter cmd = new OleDbDataAdapter(sqlQuery, conn);

cmd.SelectCommand.Parameters.Add("@cuid", OleDbType.VarChar, 20).Value =
Session["CUID"];

DataSet dsFleet = new DataSet();

cmd.Fill(dsFleet);
DataGrid1.DataSource = dsFleet;

DataGrid1.SelectedIndex = 0;

DataGrid1.DataBind();

conn.Close();

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote

in
message news:uD**************@tk2msftngp13.phx.gbl...
Brian,

Why would you loop through a data grid? If anything, I would think
that
you want to create a data adapter, and then have it update the

underlying data source based on the changes that have occured.

Also, are you using Windows Forms or ASP.NET?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Brian Conway" <Br**********@qwest.com> wrote in message
news:eI*************@TK2MSFTNGP10.phx.gbl...
> Can anyone give me an example of how I can loop through a datagrid

and have
> it run a stored procedure each time it loops?
>
>



Nov 16 '05 #7
foreach(DataRow dr in YourDataSet.Tables("YourTable")) {
//runs through every row .. you can access variables for the row
dr["Column"]
}
"Brian Conway" <Br**********@qwest.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
How do I do this?
"Greg Young" <gr********@planetbeach.com> wrote in message
news:Ov**************@TK2MSFTNGP10.phx.gbl...
it would probably be better to run through the datasource you have

connected
to it.
"Brian Conway" <Br**********@qwest.com> wrote in message
news:eI*************@TK2MSFTNGP10.phx.gbl...
Can anyone give me an example of how I can loop through a datagrid and

have
it run a stored procedure each time it loops?



Nov 16 '05 #8

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

Similar topics

2
by: CanoeGuy | last post by:
I have an array that I am populating from a database. I am looping through the array to write the values to a datagrid. At this point, I'm stuck. I can't figure out how to read the first four...
6
by: Dan | last post by:
I'd like to loop through selected datagrid rows and extract specified columns from those rows. How would I do that? Thanks... Dan
1
by: Kelvin | last post by:
Hi All, I wrote a program insert new row between rows while the datatable is looping. It display the error message. Exception Details: System.ArgumentException: This row already belongs to this...
1
by: Diva | last post by:
Hi, I have a data grid in my application. It has 20 rows and I have set the page size as 5. I have a Submit button on my form and when I click on Submit, I need to loop through the rows in the...
2
by: Jim Heavey | last post by:
Hello, I am trying to figure out how to get to the "footer" control in a datagrid. I set up the following logic: Dim cntrl As Control Dim cnt As Integer = dgNewMovies.Controls.Count For Each...
2
by: Jim Bancroft | last post by:
This may be a no-brainer, but I'm sure I follow what's happening here... I have a DataGrid with one DropDownList per row. If I select a few DropDown items and postback my page, I can't loop...
5
by: magmo | last post by:
Hi I have a datagrid that have checkboxes added to it and there is also a button that I want to use as a check what rows has been selected in the datagrid. But when I use this piece if code...
0
by: | last post by:
Greets All, Question on data in datagrid /listbox and looping? I’m trying to decide the best way to write this code. 1 would like the user to make several selections from one listbox/combo box...
0
by: | last post by:
Greets All, Question on data in datagrid /listbox and looping? I’m trying to decide the best way to write this code. 1 would like the user to make several selections from one listbox/combo box...
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: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.