How to write C# code to upload excel data to database table?

  • Thread starter Thread starter VAer8
  • Start date Start date
V

VAer8

Guest
Trying to explain the case as clearly as I can.

Let us say, I have database connection string code (see below), which works fine.

Let us say, the database is xyz, and there is table called Customer under database xyz

What I want to do: Upload the excel data into table Customer, see excel data screenshot.

Now I would like to write code for btnUpload_Click , how should I write it? Or any other comments?

Thanks.

OdbcConnection Cn;
Username = txtUsername.Text;
Password = txtPassword.Text;
ConnectionString = "Driver={Adaptive Server Enterprise};server=*****;port=*****;db=xyz;uid=" + Username + ";pwd=" + Password + ";";

Cn = new OdbcConnection(ConnectionString);
//The code works fine for this part

private void btnUpload_Click(object sender, EventArgs e) //Don't know how to write the code for this part.
{
//Click the button to browse excel file, no hard code for file path.
//The excel file has only one sheet, no hidden sheet
//The excel filename could be anything, not necessarily same as database table name Customer.
//Excel column order may not be same as database table Customer field order
//Excel title row names (CustomerName,Address,City,PostalCode,Country) are same as database table Customer filed names, but may not be in the same order.
}

1413014.jpg

Continue reading...
 
Back
Top