当excel表中的数据更新到更多列不能正常工作时 [英] When update data in excel sheet to more columns not working why

查看:65
本文介绍了当excel表中的数据更新到更多列不能正常工作时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有excel工作表名称Allprinting



包含UserID,UserName,UserNameAR,Country,CountryAR,Member,MemberAR列



如果客户更改了这些



列中的任何数据,我需要在此Excel工作表中生成更新数据(UserID,UserName,UserNameAR,Country, CountryAR,会员,会员AR)



但是轰鸣声代码对我不起作用



这样什么是问题



我的代码



I have excel sheet name Allprinting

contain to UserID,UserName,UserNameAR,Country,CountryAR,Member,MemberAR columns

I need to make update data in this excel sheet if client change any data in these

columns (UserID,UserName,UserNameAR,Country,CountryAR,Member,MemberAR)

but bellow code not working for me

so that what is the problem

my code

var fileName = string.Format("{0}\\Book502", Directory.GetCurrentDirectory());
var connection = string.Format("Provider=Microsoft.ACE.OLEDB.12.0;" + "Data Source={0};Mode=ReadWrite;Extended Properties=Excel 12.0 Xml;", fileName);
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(connection);
                MyConnection.Open();
                myCommand.Connection = MyConnection;
            sql = "Update [AllPrinting$] SET UserName=@UserName and UserNameAR=@UserNameAR and Country=@Country and CountryAR=@CountryAR AND Member=@Member AND MemberAR=@MemberAR WHERE UserID=@UserID";
           
            myCommand.CommandText = sql;
                myCommand.Parameters.AddWithValue("@UserName", textBox2.Text);
                myCommand.Parameters.AddWithValue("@UserID", textBox1.Text);
               myCommand.Parameters.AddWithValue("@UserNameAR", textBox3.Text);
            myCommand.Parameters.AddWithValue("@Country", textBox4.Text);
            myCommand.Parameters.AddWithValue("@CountryAR", textBox5.Text);
            myCommand.Parameters.AddWithValue("@Member", textBox6.Text);
            myCommand.Parameters.AddWithValue("@MemberAR", textBox7.Text);
            myCommand.ExecuteNonQuery();
                MyConnection.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }



我可以更新excel表中的数据如果我对一列进行更新


I can update data in excel sheet if i make update to one column

sql = "Update [AllPrinting$] SET UserName=@UserName and UserNameAR=@UserNameAR WHERE UserID=@UserID";





但是将数据更新到更多列不能正常工作:





But update data to more column not working as following :

sql = "Update [AllPrinting$] SET UserName=@UserName and UserNameAR=@UserNameAR and Country=@Country and CountryAR=@CountryAR AND Member=@Member AND MemberAR=@MemberAR WHERE UserID=@UserID";





我尝试了什么:



当excel表中的更新数据更多列无效时为什么



What I have tried:

when update data in excel sheet to more columns not working why

推荐答案

SET UserName = @ UserName和UserNameAR = @ UserNameAR和Country = @ Country and CountryAR = @ CountryAR AND Member = @ Member AND MemberAR = @ MemberAR WHERE UserID = @ UserID;

myCommand.CommandText = sql;
myCommand.Parameters.AddWithValue( @ UserName,textBox2.Text);
myCommand.Parameters.AddWithValue( @ UserID,textBox1.Text);
myCommand.Parameters.AddWithValue( @ UserNameAR,textBox3.Text);
myCommand.Parameters.AddWithValue( @ Country,textBox4.Text);
myCommand.Parameters.AddWithValue( @ CountryAR,textBox5.Text);
myCommand.Parameters.AddWithValue( @ Member,textBox6.Text);
myCommand.Parameters.AddWithValue( @ MemberAR,textBox7.Text);
myCommand.ExecuteNonQuery();
MyConnection.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
SET UserName=@UserName and UserNameAR=@UserNameAR and Country=@Country and CountryAR=@CountryAR AND Member=@Member AND MemberAR=@MemberAR WHERE UserID=@UserID"; myCommand.CommandText = sql; myCommand.Parameters.AddWithValue("@UserName", textBox2.Text); myCommand.Parameters.AddWithValue("@UserID", textBox1.Text); myCommand.Parameters.AddWithValue("@UserNameAR", textBox3.Text); myCommand.Parameters.AddWithValue("@Country", textBox4.Text); myCommand.Parameters.AddWithValue("@CountryAR", textBox5.Text); myCommand.Parameters.AddWithValue("@Member", textBox6.Text); myCommand.Parameters.AddWithValue("@MemberAR", textBox7.Text); myCommand.ExecuteNonQuery(); MyConnection.Close(); } catch (Exception ex) { MessageBox.Show(ex.ToString()); }



我可以更新excel表中的数据如果我对一列进行更新


I can update data in excel sheet if i make update to one column

sql = "Update [AllPrinting


SET UserName = @ UserName和UserNameAR = @ UserNameAR WHERE UserID = @ UserID;
SET UserName=@UserName and UserNameAR=@UserNameAR WHERE UserID=@UserID";





但是将数据更新到更多列不能正常工作:





But update data to more column not working as following :

sql = "Update [AllPrinting


SET UserName = @ UserName和UserNameAR = @ UserNameAR和Country = @ Country和CountryAR = @ CountryAR AND Member = @ Member AND MemberAR = @ MemberAR WHERE UserID = @ UserID;
SET UserName=@UserName and UserNameAR=@UserNameAR and Country=@Country and CountryAR=@CountryAR AND Member=@Member AND MemberAR=@MemberAR WHERE UserID=@UserID";





我的尝试:



将excel表格中的数据更新为更多不起作用的列



What I have tried:

when update data in excel sheet to more columns not working why


这篇关于当excel表中的数据更新到更多列不能正常工作时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆