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)