将错误输入UPDATE查询 [英] Getting error into UPDATE query

查看:89
本文介绍了将错误输入UPDATE查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下代码用于更新excel表中的记录: -



尝试

{

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.ACE.OLEDB.12.0; Data Source = d:\\csharp.net-informations.xlsx; Extended属性= Excel 12.0 Xml;);

MyConnection.Open();

myCommand.Connection = MyConnection;



sql =(@更新[Sheet1 $] set(candidatefname ='+ txtFName.Text +',candidatemname ='+ txtMName.Text +',candidatelname ='+ txtLName.Text +' ,dob ='+ dtpDOB.Value +',sex ='+ cmbSex.Text +',currentaddress ='+ txtCurrentAddress.Text +',permanentaddress ='+ txtParmanentAddress.Text +',mobilenumber ='+ txtMobil e.Text +',mailid ='+ txtMailID.Text +',maritalstatus ='+ cmbMaritalStatus.Text +',experience ='+ txtExperience.Text +',departmentname ='+ cmbDepartment。文字+')其中SrNo ='+ cID +');

myCommand.CommandText = sql;

myCommand.ExecuteNonQuery();

MyConnection.Close();

}

catch(例外情况)

{

MessageBox .Show(ex.ToString());

}





我得到了错误: UPDATE语句中的语法错误。



当我调试代码时,我想要完全获得所有值,但是在sql中对象我得到空值。



所以请有人告诉我这有什么问题吗?

解决方案

< blockquote> set(candidatefname ='+ txtFName.Text +',candidatemname ='+ txtMName.Text +',candidatelname ='+ txtLName.Text +', dob ='+ dtpDOB.Value +',sex ='+ cmbSex.Text +',currentaddress ='+ txtCurrentAddress.Text +',permanentaddress ='+ txtParmanentAddress.Text +',mobilenumber = '+ txtMobile.Text +',mailid ='+ txtMailID.Text +',maritalstatus ='+ cmbMaritalStatus.Text +',experience ='+ txtExperience.Text +',departmentname =' + cmbDepartment.Text +')其中SrNo ='+ cID +');

myCommand.CommandText = sql;

myCommand.ExecuteNonQuery();

MyConnection.Close();

}

catch(例外情况)

{

MessageBox.Show(ex.ToString());

}





我收到错误: UPDATE语句中的语法错误。



当我调试代码时,我想要完全获得所有值,但在sql对象中我得到空值。



所以请任何人告诉我什么这是错误的吗?


更新查询语法错误 - 更新表设置字段= newvalue where criteria ...

你用过(之后设置。

请删除(之后设置并删除)之前


删除(&)后面的SQL中的设置它会工作



(@更新[Sheet1


Below code is for update the record in excel sheet:-

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.ACE.OLEDB.12.0;Data Source=d:\\csharp.net-informations.xlsx;Extended Properties=Excel 12.0 Xml;");
MyConnection.Open();
myCommand.Connection = MyConnection;

sql = (@"Update [Sheet1$] set (candidatefname='" + txtFName.Text + "', candidatemname='" + txtMName.Text + "', candidatelname='" + txtLName.Text + "', dob='" + dtpDOB.Value + "', sex='" + cmbSex.Text + "', currentaddress='" + txtCurrentAddress.Text + "', permanentaddress='" + txtParmanentAddress.Text + "', mobilenumber='" + txtMobile.Text + "', mailid='" + txtMailID.Text + "', maritalstatus='" + cmbMaritalStatus.Text + "', experience='" + txtExperience.Text + "', departmentname='" + cmbDepartment.Text + "') where SrNo='" + cID + "' ");
myCommand.CommandText = sql;
myCommand.ExecuteNonQuery();
MyConnection.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}


I am getting the error : Syntax error in UPDATE statement.

When I am debugging the code getting all the value perfectly as I want, but in sql object I am getting null value.

So please can anybody tell me what is wrong with this?

解决方案

set (candidatefname='" + txtFName.Text + "', candidatemname='" + txtMName.Text + "', candidatelname='" + txtLName.Text + "', dob='" + dtpDOB.Value + "', sex='" + cmbSex.Text + "', currentaddress='" + txtCurrentAddress.Text + "', permanentaddress='" + txtParmanentAddress.Text + "', mobilenumber='" + txtMobile.Text + "', mailid='" + txtMailID.Text + "', maritalstatus='" + cmbMaritalStatus.Text + "', experience='" + txtExperience.Text + "', departmentname='" + cmbDepartment.Text + "') where SrNo='" + cID + "' ");
myCommand.CommandText = sql;
myCommand.ExecuteNonQuery();
MyConnection.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}


I am getting the error : Syntax error in UPDATE statement.

When I am debugging the code getting all the value perfectly as I want, but in sql object I am getting null value.

So please can anybody tell me what is wrong with this?


Update query syntax is wrong - update table set field = newvalue where criteria...
you have used "(" after set .
please remove "(" after set and also remove ")" before where


Remove "(" & ")" after "set" in the SQL it will work

(@"Update [Sheet1


这篇关于将错误输入UPDATE查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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