Solved

Help with c# project

Posted on 2003-12-03
5
229 Views
Last Modified: 2010-04-16
this is what i have to do:

Write a C# Windows Forms application that is capable of reading in a CSV file
and writing the records to an Access table.

 

The Comma Separated Value file will be a predefined format (see below).
You will need to create an MS Access database containing a table called Customers
with the following record schema:

 

CustNum           integer

LastName         Text (25)

FirstName         Text (20)

Address            Text (30)

City                  Text (20)

Postal               Text (10)

 

Test your program using the following input data:

 

"CustNum","LastName","FirstName","Address","City","Postal"

"0001","Smith","Billy-Bob","123 Small St.","London","N7R 2X6"

"0002","Jones","Mary-Lou","456 Big St.","London","N7H 5B7"

"0003","Peterson","Mike","789 Medium Ave.","Waterloo","N8H 1C6"

 

Your window must contain only 2 buttons (Load CSV and Cancel) and a
text box (defining the CSV input file name). Your input file name should
default to the name Customers.txt (included with the project zip file) and your
output database should be called Customers.mdb.

 

Important:

 

You must use 100% C# code to connect to the Access database and insert the records.

Use StreamReader to input the CSV records and parse out each field in each row using
suitable string processing techniques.

this is what i have:(the one i have is backwareds to the description up there i need to know how i can go the other way like in the description)

private void output_Click(object sender, System.EventArgs e)
            {
                  OleDbDataAdapter da;
                  DataSet ds = null;
                  string connS = @"Provider=Microsoft.JET.OLEDB.4.0;data source=ppp2.mdb";
                  
                  ds = new DataSet();
                  OleDbConnection connection = new OleDbConnection(connS);
                  string sqlString = "SELECT * FROM PARTS";
                  da =new OleDbDataAdapter(sqlString,connection);

                  try
                  {
                        da.Fill(ds,"parts");

                  }
                  catch(Exception ex)
                  {
                        MessageBox.Show("Problem with DB access-\n\n" + ex.ToString());
                        return;
                  }

                  int[] F1 = new int[ds.Tables["Parts"].Rows.Count];
                  string[] F2 = new string[ds.Tables["Parts"].Rows.Count];
                  string[] F3 = new string[ds.Tables["Parts"].Rows.Count];
                  int[] F4 = new int[ds.Tables["Parts"].Rows.Count];

                  for(int i=0;i<ds.Tables["Parts"].Rows.Count;i++)
                  {
                        F1[i]=(int)ds.Tables["Parts"].Rows[i]["PartNumber"];
                        F2[i]=(string) ds.Tables["Parts"].Rows[i]["Description"];
                        F3[i]= (string) ds.Tables["Parts"].Rows[i]["Location"];
                        F4[i]=(int)ds.Tables["Parts"].Rows[i]["QOH"];
                  }
                  FileStream fs = new FileStream("Parts.txt",FileMode.Create);
                  StreamWriter sr = new StreamWriter(fs);
 
                  for(int i=0;i<ds.Tables["Parts"].Rows.Count;i++)
                  {
                        sr.WriteLine(F1[i]+","+F2[i]+","+F3[i]+","+F4[i]);
                  }
                  connection.Close();
                  sr.Close();
                        
            }
0
Comment
Question by:roman100
[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
5 Comments
 
LVL 10

Expert Comment

by:smegghead
ID: 9871497
Homework ??
0
 

Author Comment

by:roman100
ID: 9872170
ya its part of a big assignment
0
 
LVL 8

Accepted Solution

by:
gregasm earned 100 total points
ID: 10464936
Im not going to do your homework for you! hahaah
But this the framework I would use.

//Create some constants that use use an index to keep track of the column name.

private const int CustNum = 0;
private const int LastName = 1;

//Then open the FileStream
System.IO.FileStream fs = new System.IO.FileStream("csv.text");
System.IO.TextReader tr= new System.IO.TextReader(fs);

//load the current line from the file into an array
string line;
While ((line = tr.ReadLine()) != null)
{
     string[] newRow = line.Split(",");
     //and then add the array values to your dataTable based on the
     //constants (indexes) declared above..
     DataRow dr = myTable.NewRow();
    dr[CustNum] = newRow[custNum];
    dr[LastName] = newRow[LastName];
    .....
     //add the row to the datatable.
     myTable.Rows.Add(dr);
}

  Hope this helps.
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
C# LINQ ForEach() question 6 84
tableview is not updating 1 28
JQuery Detecting page post back 6 19
Selenium and Xpath 4 30
In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

749 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