Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / July 2005

Tip: Looking for answers? Try searching our database.

Read Comma Delimited File

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Luis Esteban Valencia - 27 Jul 2005 14:05 GMT
Hello. I have a  method that receives a customer number, and it must return
the customer credit which is in a file. like this.

So if the parameter is 1, it must give me 450000.

1,450000
2,60000
3,34000
4,780000
5,99000
10,45000
11,340000
12,45000
13,56000
14,56000
15,20000
16,90000
17,99999
18,23090
19,34434
20,34534

Thanks
Mark Rae - 27 Jul 2005 14:22 GMT
> Hello. I have a  method that receives a customer number, and it must
> return
> the customer credit which is in a file. like this.
>
> So if the parameter is 1, it must give me 450000.

Several ways:

1) Open the file into a StreamReader object, read each line in turn and
Split() it into an array, looping till you find the line you're looking for

2) Use ADO.NET, OleDb and the Jet provider to treat the file like a database
table and then run a simple SELECT statement against it
Luis Esteban Valencia - 27 Jul 2005 14:42 GMT
I already did but I got an error.

[WebMethod]

public int traerCredito(int cliente)

{

StreamReader sr;

string linea;

try

{

sr=File.OpenText(archivo);

while (sr.Peek() != -1)

{

linea= sr.ReadLine();

char[] splitter = {','};

string[] otr= linea.Split(splitter, 2);

if (otr[0].ToString() == cliente.ToString())

{

return Convert.ToInt32(otr[1]);

}

else

{

return -1;

}

}

}

catch(Exception ex)

{

//throw ex;

return -1;

}

}

The error is:

:\inetpub\wwwroot\WSCreditCheck\CreditCheck.asmx.cs(61):
'WSCreditCheck.CreditCheck.traerCredito(int)': no todas las rutas de código
devuelven un valor

Not all the paths return a value.??

Why??

> > Hello. I have a  method that receives a customer number, and it must
> > return
[quoted text clipped - 9 lines]
> 2) Use ADO.NET, OleDb and the Jet provider to treat the file like a database
> table and then run a simple SELECT statement against it
Mark Rae - 27 Jul 2005 14:58 GMT
> Not all the paths return a value.??

Try this:

public int traerCredito(int cliente)
{
StreamReader sr;
string linea;
int intReturn = 0;
/*
>0 = found
0 = not found
-1 = error
*/

try
{
 sr=File.OpenText(archivo);
 while (sr.Peek() != -1)
 {
  linea= sr.ReadLine();
  char[] splitter = {','};
  string[] otr= linea.Split(splitter, 2);
  if (otr[0].ToString() == cliente.ToString())
  {
   intReturn = Convert.ToInt32(otr[1]);
   break;
  }
 }
 return intReturn;
}
catch(Exception ex)
{
 //throw ex;
 return -1;
}
}
Paul Clement - 27 Jul 2005 16:22 GMT
¤ Hello. I have a  method that receives a customer number, and it must return
¤ the customer credit which is in a file. like this.
¤
¤ So if the parameter is 1, it must give me 450000.
¤
¤
¤ 1,450000
¤ 2,60000
¤ 3,34000
¤ 4,780000
¤ 5,99000
¤ 10,45000
¤ 11,340000
¤ 12,45000
¤ 13,56000
¤ 14,56000
¤ 15,20000
¤ 16,90000
¤ 17,99999
¤ 18,23090
¤ 19,34434
¤ 20,34534
¤

The ADO.NET method (you could also use a DataReader):

       Dim ConnectionString As String

       ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
           "Data Source=" & "E:\My Documents\TextFiles" & ";" & _
           "Extended Properties=""Text;HDR=No"""

       Dim TextConnection As New System.Data.OleDb.OleDbConnection(ConnectionString)
       TextConnection.Open()

       Dim da As New System.Data.OleDb.OleDbDataAdapter("SELECT * FROM FileName#csv WHERE F1='1'",
TextConnection)

       Dim ds As New DataSet("TextFiles")
       da.Fill(ds, "CSV")
       Dim dt As DataTable
       dt = ds.Tables("CSV")

       Dim drCurrent As DataRow
       For Each drCurrent In dt.Rows
            Console.WriteLine(drCurrent.Item(0).ToString)
            Console.WriteLine(drCurrent.Item(1).ToString)
      Next

Paul
~~~~
Microsoft MVP (Visual Basic)

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.