?
Solved

ASP.NET/ADO - DataSet Tables

Posted on 2005-03-05
4
Medium Priority
?
518 Views
Last Modified: 2006-11-17
I am trying to put together a simple program to read in a comma delimited file and store to database table but I am getting an error with my dataset "Cannot find table 0."

SqlCommand cmdSql = new SqlCommand( "Select Top 1 From Mytable", conn );
DataSet ds = new DataSet();
conn.Open();
dg.DataSource = cmdSql.ExecuteReader();
dg.DataBind();
conn.Close();
.
RowCounter++;
.

foreach (string a in split)
{
ds.Tables[0].Rows[RowCounter][ColCounter]= a;   "Error occurs here"  
ColCounter++;
}
 
I am just trying to copy the contents from my text file to a column in the DatSet table.  What am I missing?
0
Comment
Question by:Hojoformo
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 2

Expert Comment

by:Coolhand2120
ID: 13468555
I had this probelm too, you must change your select statement to read somthing more like :

strPath = Server.MapPath("/")
set objConnection=Server.CreateObject("ADODB.Connection")
objConnection.Open "Driver={Microsoft Text Driver (*.txt; *.csv)};Dbq=" & strPath & "\somedirectory\" & ";Extensions=asc,csv,tab,txt"
strSQL = "Select * From " & uploadname  '<--------------------Here you must have the FILENAME of the file you're trying to read from
set objRS=Server.CreateObject("ADODB.RecordSet")
objRS.Open strSQL, objConnection,3,3
arrRows=objRS.GetRows()
set objRS = nothing
set objConnection = nothing

You don't have to use this method, just understand that the SQL statement must contain the file name of the file you are parseing.  If you're using an upload componet you can usualy find this value somewhere in it's object collection.

Sorry my only example is in VB, but the object syntax is the same.

-Coolhand2120
0
 

Author Comment

by:Hojoformo
ID: 13468703
Actually, I only posted a small portion of the code.  I am using the streamreader object to read my txt file.  I am having a problem with assigning the contents of the text file to a column of my dataset.  There is something wrong with this line of code "ds.Tables[0].Rows[RowCounter][ColCounter]= a;".   I am new to asp.net/ado so I am sure it is something simple.    The error i get is "Cannot find table 0."  ANy other suggestions?  Thanks!

filetoread = Server.MapPath("test2.txt");
StreamReader reader = new StreamReader(filetoread);
for (string readcontents = reader.ReadLine(); readcontents != null; readcontents = reader.ReadLine())
{
  char [] delimiter = textdelimiter.ToCharArray();
  splitout = readcontents;
  String [] split = null;
  split = readcontents.Split(delimiter);
  ColCounter = 0;

  foreach (string a in split)
  {                          
    ds.Tables[0].Rows[RowCounter][ColCounter]= a;    ///// error - Cannot find table 0."
    ColCounter++;
   }
                        
RowCounter++;
0
 

Author Comment

by:Hojoformo
ID: 13468745
I see the problem.  I was just missing the "fill".    Thanks for your help!

da.Fill(ds, "Mytable");
0
 
LVL 2

Accepted Solution

by:
Coolhand2120 earned 1500 total points
ID: 13468973
NP!  Glad you figured it out!

-Coolhand2120
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question