如何在Excel工作表上更新数据? [英] How Can I Update Data On Excel Sheet?
本文介绍了如何在Excel工作表上更新数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
private void button5_Click(object sender, EventArgs e)
{
string team = comboBox3.SelectedText;
string name = textBox1.Text;
DateTime result = dateTimePicker1.Value.Date;
string date1 = result.ToString("dd/MM/yyyy");
DateTime result2 = dateTimePicker2.Value.Date;
string date2 = result2.ToString("dd/MM/yyyy");
try
{
System.Data.OleDb.OleDbConnection MyConnection;
System.Data.OleDb.OleDbCommand myCommand = new System.Data.OleDb.OleDbCommand();
string sql = null;
MyConnection = new System.Data.OleDb.OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0;Data Source='d:\\enquiry1/enquiry-Excel.xls';Extended Properties=Excel 8.0;");
MyConnection.Open();
myCommand.Connection = MyConnection;
sql = "Update [Sheet1$] set FinalStatus='Succeed' where [Name]='" + name + "' and [Team]='" + team + "' and [Date]='" + date1 + "' and [Req Date]='" + date2 + "'";
myCommand.CommandText = sql;
myCommand.ExecuteNonQuery();
MyConnection.Close();
MessageBox.Show("Successfully Saved");
}
代码将成功执行。但是在excel文件中没有任何变化?
如果我通过将值放在
这样的Sql查询来运行它?
Code will successfully execute. but nothing change in the excel file?
if i run this by putting values on
Sql query like this?
sql = "Update [Sheet1$] set FinalStatus='Succeed' where Name='down' and Team='Group 1'";
它会起作用吗?但我想得到文本框值,日期值,并根据我需要搜索数据?
it's gonna work? but i want to get textbox values , date values and according to that i need to search the data?
推荐答案
设置FinalStatus ='成功',其中[Name] =' + name + '和[Team] =' + team + '和[Date] =' + date1 + '和[Req Date] =' + date2 + ';
myCommand.CommandText = sql;
myCommand.ExecuteNonQuery();
MyConnection.Close();
MessageBox.Show(< span class =code-string> 已成功保存);
}
set FinalStatus='Succeed' where [Name]='" + name + "' and [Team]='" + team + "' and [Date]='" + date1 + "' and [Req Date]='" + date2 + "'"; myCommand.CommandText = sql; myCommand.ExecuteNonQuery(); MyConnection.Close(); MessageBox.Show("Successfully Saved"); }
代码将成功执行。但excel文件中没有任何变化?
如果我通过将值放在
像这样的SQL查询?
Code will successfully execute. but nothing change in the excel file?
if i run this by putting values on
Sql query like this?
sql = "Update [Sheet1
设置FinalStatus ='Succeed',其中Name ='down'和Team ='Group 1';
set FinalStatus='Succeed' where Name='down' and Team='Group 1'";
它会起作用吗?但我想得到文本框值,日期值,并根据我需要搜索数据?
it's gonna work? but i want to get textbox values , date values and according to that i need to search the data?
使用参数化查询
use parameterized query
sql = "Update [Sheet1
这篇关于如何在Excel工作表上更新数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文