Hello there, I have a problem with my program. i need to upload to SQL Server database different files. The flow is like this:
file sender 1 = megan (constant file sender 1)
kind of file = .doc (constant kind of file)
file sender 2 = bumblebee (constant file sender 2)
kind of file = .pdf (constant kind of file)
file sender 3 = megatron (constant file sender 3)
kind of file = .xls (constant kind of file)
when the server receives the uploaded file from sender 1 = the program needs to open and read the doc file then transfer the content by rows and columns to table megan
when the server receives the uploaded file from sender 2 = the program needs to open and read the pdf file then transfer the content by rows and columns to table bumblebee
when the server receives the uploaded file from sender 3 = the program needs to open and read the xls file then transfer the content by rows and columns to table bumblebee
ex. doc file
name address tel. no age account number = constant format
what syntax i will use for the program c# to open and read the uploaded. then transfer to db table by rows and columns.
thanks a lot,
your help will be very much appreciated.
Arnold
Different files to SQL Server
Page 1 of 12 Replies - 513 Views - Last Post: 19 June 2009 - 08:45 AM
Replies To: Different files to SQL Server
#2
Re: Different files to SQL Server
Posted 19 June 2009 - 07:55 AM
Dream.In.Code has a policy by which we prefer to see a good faith effort on your part before providing source code for homework assignments. Please post the code you have written in an effort to resolve the problem, and our members would be happy to provide some guidance. Be sure to include a description of any errors you are encountering as well.
Post your code like this:
Thanks.
Post your code like this:
Thanks.
#3
Re: Different files to SQL Server
Posted 19 June 2009 - 08:45 AM
Hello PsycoCoder,
This is my sample working code parsing an excel file to db, but for .doc, .pdf, etc. etc how will it work?;
code:
This is my sample working code parsing an excel file to db, but for .doc, .pdf, etc. etc how will it work?;
code:
{
class EngineExcel1 : BatchFileEngine
{
public override bool IsValid()
{
// get extension, check if extension is .xls
string extension = GetExtension();
if (extension.CompareTo("xls") == 0)
return true;
return false;
}
public override void Process()
{
// step 1: create batch
Batch batch = new Batch();
batch.DateIn = DateTime.Now;
batch.TotalAmount = 0;
batch.Status = BatchStatus.Uploaded;
batch.Stage = BatchStage.Uploading;
batch.TransactionCount = 0;
batch.CurrencyID = (int) TieUp.FundingCurrency;
batch.TieUpID = TieUp.ID;
batch.Balance = 0;
BatchRepo batch_repo = new BatchRepo();
batch_repo.Add(batch);
batch_repo.Save();
// we're parsing an excel .xls file
string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=\"" + FileName + "\";Extended Properties=\"Excel 8.0;HDR=YES;\"";
OleDbConnection dbConnection = new OleDbConnection(@connectionString);
dbConnection.Open();
try
{
OleDbCommand dbCommand = new OleDbCommand("SELECT * FROM [Sheet1$]", dbConnection);
OleDbDataReader dbReader = dbCommand.ExecuteReader();
TransactionRemitterRepo remitter_repo = new TransactionRemitterRepo();
TransactionBeneficiaryRepo bene_repo = new TransactionBeneficiaryRepo();
// step 2: go through the individual rows
while (dbReader.Read())
{
decimal amount = Convert.ToDecimal(dbReader["PHP"].ToString());
// step 3: create transactions
Transaction trans = new Transaction();
trans.ReferenceID = dbReader["REF# NO"].ToString();
trans.ValueDate = batch.DateIn; // default to now, since we don't have a value date in the excel file
trans.TransactionDate = batch.DateIn; // always now
trans.Amount = amount;
trans.DeliveryType = DeliveryType.Get(dbReader["TRANSFER TYPE"].ToString());
trans.Status = TransactionStatus.New;
trans.BatchID = batch.ID;
trans.TieUpID = TieUp.ID;
TransactionRepo trans_repo = new TransactionRepo();
trans_repo.Add(trans);
trans_repo.Save();
// step 4: create remitter (pre-merge)
TransactionRemitter remitter = new TransactionRemitter();
remitter.TransactionID = trans.ID;
remitter.Name = dbReader["SENDER"].ToString();
remitter.ContactNumber = dbReader["SENDER TEL# NO"].ToString();
remitter_repo.Add(remitter);
// step 5: create beneficiary (pre-merge)
TransactionBeneficiary beneficiary = new TransactionBeneficiary();
beneficiary.TransactionID = trans.ID;
beneficiary.Name = dbReader["BENEFICIARY NAME"].ToString();
beneficiary.ContactNumber = dbReader["BENEFICIARY CONTACT NO#"].ToString();
beneficiary.Address = dbReader["BENEFICIARY/ADDRESS"].ToString();
bene_repo.Add(beneficiary);
}
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote



|