Im trying to loop through the rows of my DataTable but keeping getting an error...
Ive already set the datatable and rows with
Dim rowRunData
As System.Data.DataRow
Dim ProjectData =
New System.Data.DataTable()
And Ive put the various data in the datatable.... so my code for looping I thought would be....
For Each rowRunData
In ProjectData
DoStuff()
Next
But with this im getting the following error:
Unable to cast object of type 'System.Data.DataTable' to type 'System.Collections.IEnumerable'.
Any one can guide me in Import the Excel 2002 data into sql server 2000 using ado.net1.1. I have searched all the forums most of the solutions end with a line of suggestion not with any code .
here is my code . by using OLEDB JET I got the data from Excel to data set , the data is in the data table
OleDbConnection strConn = new OleDbConnection ("Provider=Microsoft.Jet.OLEDB.4.0;data source= c:\\1005.xls;Extended Properties=\"Excel 8.0;HDR=YES\"");
OleDbDataAdapter myCommand = new OleDbDataAdapter("SELECT * FROM [sheet1$]",strConn);
DataSet dataSet = new DataSet();
myCommand.Fill(dataSet);
DataTable mytable;
mytable= dataSet.Tables[0];
I can view this data on the datagrid .
now I want to transfer this data in to SQL server . I tryed as below but I was end up with nothing
if(mytable.Rows.Count>0)
{
try
{
// connect to sql andinsert the data
OleDbConnection conn = new OleDbConnection ("Provider=SQLOLEDB;Data Source=;Initial Catalog=;");
I was end up here just by making connection to SQL server . Can some one assist me further . I am a beginner.I tryed loop like this
foreach (DataRow dr in mytable.Rows)
{
foreach (DataColumn dc in mytable.Columns)
{
string val = dr[dc].ToString();
Response.Write(val);
}
I can see the string values but no ides how to transfer the data in the table "mytable ' in to sql server</div>
boomers
Member
312 Points
100 Posts
How To Loop Through Datatable
Jan 03, 2007 04:46 PM|LINK
Im trying to loop through the rows of my DataTable but keeping getting an error...
Ive already set the datatable and rows with
Dim rowRunData As System.Data.DataRowDim ProjectData = New System.Data.DataTable() And Ive put the various data in the datatable.... so my code for looping I thought would be....
For Each rowRunData In ProjectData
DoStuff()
Next
But with this im getting the following error:
Unable to cast object of type 'System.Data.DataTable' to type 'System.Collections.IEnumerable'.
Any help would be very much appreciated
Database DataTable ADO.NET looping
joteke
All-Star
46284 Points
6896 Posts
ASPInsiders
MVP
Re: How To Loop Through Datatable
Jan 03, 2007 05:12 PM|LINK
Hi,
For Each rowRunData In ProjectData.Rows
DoStuff()
Next
Teemu Keiski
Finland, EU
boomers
Member
312 Points
100 Posts
Re: How To Loop Through Datatable
Jan 03, 2007 06:15 PM|LINK
Many thanks to you :)
jayfeb29
Member
4 Points
2 Posts
Import data from Excel to Sql Server using Ado.net
Jan 04, 2007 08:06 PM|LINK
Any one can guide me in Import the Excel 2002 data into sql server 2000 using ado.net1.1. I have searched all the forums most of the solutions end with a line of suggestion not with any code .
here is my code . by using OLEDB JET I got the data from Excel to data set , the data is in the data table
OleDbConnection strConn = new OleDbConnection ("Provider=Microsoft.Jet.OLEDB.4.0;data source= c:\\1005.xls;Extended Properties=\"Excel 8.0;HDR=YES\"");
OleDbDataAdapter myCommand = new OleDbDataAdapter("SELECT * FROM [sheet1$]",strConn);
DataSet dataSet = new DataSet();
myCommand.Fill(dataSet);
DataTable mytable;
mytable= dataSet.Tables[0];
I can view this data on the datagrid .
now I want to transfer this data in to SQL server . I tryed as below but I was end up with nothing
if(mytable.Rows.Count>0)
{
try
{
// connect to sql andinsert the data
OleDbConnection conn = new OleDbConnection ("Provider=SQLOLEDB;Data Source=;Initial Catalog=;");
I was end up here just by making connection to SQL server . Can some one assist me further . I am a beginner.I tryed loop like this
foreach (DataRow dr in mytable.Rows)
{
foreach (DataColumn dc in mytable.Columns)
{
string val = dr[dc].ToString();
Response.Write(val);
}
I can see the string values but no ides how to transfer the data in the table "mytable ' in to sql server</div>
SheoNarayan
Member
624 Points
100 Posts
Re: How To Loop Through Datatable
Oct 09, 2007 11:49 PM|LINK
Following article best suits your need.
http://www.dotnetfunda.com/articles/article12.aspx
Thanks
ASP.NET Online Training
500+ ASP.NET real time web development tips & tricks