0

I used this code for import data from Excel Sheet into database and now i want to do the opposite.

private void pictureBox1_Click(object sender, EventArgs e)
    {
        string pach = @"D:\C# Projects\P.xlsx";
        var exlData = new ExcelQueryFactory(pach);
        var data = from x in exlData.Worksheet<excelData>("Sheet1")
                   select x;
        DataClassesDataContext db = new DataClassesDataContext();
        foreach (var d in data)
        {
            db.tbl_PrsInfos.InsertOnSubmit(new tbl_PrsInfo
            {
                Id = d.Id,
                FullName = d.FullName,
                Personnely = d.Personnely,
                CodeBank = d.CodeBank,
                Bank = d.Bank,
                Email = d.Email,
                State = d.State,
            });
        }
        db.SubmitChanges();
        dgv_prs_add.DataSource = from show in db.tbl_PrsInfos select show;
    }

1 Answer 1

1

It looks like you're using the LinqToExcel library which is a read only interface for Excel sheets.

To write an Excel file you have a few options:

  • Use a third party library to write an Excel file without requiring Excel to be installed (for example the library from Aspose)
  • Write a CSV file using in-built C# file writing functions and open the CSV in Excel
  • Use office automation to create an Excel file programmatically. This requires Excel to be installed.
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.