如何通过asp.net中的gridview更新Excel [英] how to update excel through gridview in asp.net
问题描述
这是我的代码:
Hi, this is my code:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
String strConn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=F:\\Book1.xlsx;Extended Properties=Excel 8.0;";
DataTable ds = new DataTable();
OleDbDataAdapter da = new OleDbDataAdapter("Select * from[Sheet1$]", strConn);
da.Fill(ds);
grvPatient.DataSource = ds;
grvPatient.DataBind();
}
}
string PatientId = "";
protected void btn_save(object sender, EventArgs e)
{
for (int i = 0; i < grvPatient.Rows.Count; i++)
{
bool chk = ((CheckBox)grvPatient.Rows[i].FindControl("myCheckBox")).Checked;
if (chk == true)
{
PatientId = grvPatient.Rows[i].Cells[1].Text;
string Patient = grvPatient.Rows[i].Cells[2].Text;
string Amount = grvPatient.Rows[i].Cells[3].Text;
string Doctor = grvPatient.Rows[i].Cells[4].Text;
string status = grvPatient.Rows[i].Cells[5].Text;
dbquery.InsertChecked(Int32.Parse(PatientId), Patient, Int32.Parse(Amount), Doctor);
dbquery.deleteRecord(Int32.Parse(PatientId));
//update the status to MS Excel
String strConn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=F:\\Book1.xlsx;Extended Properties=Excel 8.0;";
DataTable ds = new DataTable();
OleDbDataAdapter da = new OleDbDataAdapter("Select * from[Sheet1$]", strConn);
da.Fill(ds);
grvPatient.DataSource = ds;
grvPatient.DataBind();
}
}
}
我正在尝试通过gridview更新Excel中的记录.
我有3条这样的记录:
1个Mathi b.sc
2 suruthi m.a
我在Excel中有这样的想法,并且在gridview asp.net中添加了一个复选框.如果我选中此复选框,它想删除gridview和Excel中的记录.我将Excel内容导入到网格中,所以想通过网格更新Excel,有什么想法吗?
I am trying to update the records in Excel through gridview.
I have three records like this:
1 mathi b.sc
2 suruthi m.a
I have like this in my Excel and I have added a checkbox in gridview asp.net. If I check the checkbox it wants to delete the record in gridview and Excel. I imported the Excel content to grid, so I want to update Excel through grid, any ideas?
推荐答案
",strConn); da.Fill(ds); grvPatient.DataSource = ds; grvPatient.DataBind(); } } 字符串 PatientId = " ; 受保护的 无效 btn_save(对象发件人,EventArgs e) { for ( int i = 0 ; i < grvPatient.Rows.Count; i ++) { 布尔 chk =((CheckBox)grvPatient.Rows [i] .FindControl(" )). 如果(chk == 真) { PatientId = grvPatient.Rows [i] .Cells [ 1 ].Text; 字符串 Patient = grvPatient.Rows [i] .Cells [ 2 ].Text; 字符串数量= grvPatient.Rows [i] .Cells [ 3 ].Text; 字符串 Doctor = grvPatient.Rows [i] .Cells [ 4 ].Text; 字符串 status = grvPatient.Rows [i] .Cells [ 5 ].Text; dbquery.InsertChecked( Int32 .Parse(PatientId),患者, Int32 .Parse(Amount),Doctor) ; dbquery.deleteRecord( Int32 .Parse(PatientId)); // 将状态更新为MS Excel 字符串 strConn = " ; DataTable ds = 新 DataTable(); OleDbDataAdapter da = 新建 OleDbDataAdapter("
", strConn); da.Fill(ds); grvPatient.DataSource = ds; grvPatient.DataBind(); } } string PatientId = ""; protected void btn_save(object sender, EventArgs e) { for (int i = 0; i < grvPatient.Rows.Count; i++) { bool chk = ((CheckBox)grvPatient.Rows[i].FindControl("myCheckBox")).Checked; if (chk == true) { PatientId = grvPatient.Rows[i].Cells[1].Text; string Patient = grvPatient.Rows[i].Cells[2].Text; string Amount = grvPatient.Rows[i].Cells[3].Text; string Doctor = grvPatient.Rows[i].Cells[4].Text; string status = grvPatient.Rows[i].Cells[5].Text; dbquery.InsertChecked(Int32.Parse(PatientId), Patient, Int32.Parse(Amount), Doctor); dbquery.deleteRecord(Int32.Parse(PatientId)); //update the status to MS Excel String strConn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=F:\\Book1.xlsx;Extended Properties=Excel 8.0;"; DataTable ds = new DataTable(); OleDbDataAdapter da = new OleDbDataAdapter("Select * from[Sheet1
",strConn); da.Fill(ds); grvPatient.DataSource = ds; grvPatient.DataBind(); } } }
", strConn); da.Fill(ds); grvPatient.DataSource = ds; grvPatient.DataBind(); } } }
我正在尝试通过gridview更新Excel中的记录.
我有3条这样的记录:
1个Mathi b.sc
2 suruthi m.a
我在Excel中有这样的想法,并且在gridview asp.net中添加了一个复选框.如果我选中此复选框,它想删除gridview和Excel中的记录.我将Excel内容导入到网格中,所以我想通过网格更新Excel,有什么想法吗?
I am trying to update the records in Excel through gridview.
I have three records like this:
1 mathi b.sc
2 suruthi m.a
I have like this in my Excel and I have added a checkbox in gridview asp.net. If I check the checkbox it wants to delete the record in gridview and Excel. I imported the Excel content to grid, so I want to update Excel through grid, any ideas?
请访问此链接.对您非常有用
http://www.dotnetfunda.com /articles/article1370-reading-opening-excel-file-in-csharp-using-microsoftofficeintropexcel-objec-.aspx [
hi visit this link . its very useful to you
http://www.dotnetfunda.com/articles/article1370-reading-opening-excel-file-in-csharp-using-microsoftofficeintropexcel-objec-.aspx[^]
这篇关于如何通过asp.net中的gridview更新Excel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!