本文介绍了尝试更新MS Access时出现语法错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
它说语法错误,但我的一句话似乎没问题,这里有什么问题吗?
public void updatedata( string EN_NO, string MName, string MAddress, string 社会, string 组, string 联系方式)
{
OleDbCommand updatenow = new OleDbCommand();
con.Open();
updatenow.Connection = con;
updatenow.CommandText = update成员集MName =?,MAddress = ?,社会= ?,组= ?,Contact =?其中EN_NO =?;
updatenow.Parameters.Add( EN_NO, OleDbType.VarWChar);
updatenow.Parameters [ EN_NO]。Value = EN_NO;
updatenow.Parameters.Add( MName,OleDbType.VarWChar) ;
updatenow.Parameters [ MName]。Value = MName;
updatenow.Parameters.Add( MAddress,OleDbType.VarWChar) ;
updatenow.Parameters [ MAddress]。Value = MAddress;
updatenow.Parameters.Add( 社会,OleDbType.VarWChar) ;
updatenow.Parameters [ 社会]。价值=社会;
updatenow.Parameters.Add( Group,OleDbType.VarWChar) ;
updatenow.Parameters [ Group]。Value = Group;
updatenow.Parameters.Add( 联系人,OleDbType.VarWChar) ;
updatenow.Parameters [ 联系人]。值=联系人;
尝试
{
int count = updatenow .ExecuteNonQuery();
if (count > 0 )
{
MessageBox.Show( 成功记录更新的, Methodist Church,MessageBoxButtons.OK,MessageBoxIcon.Information);
}
}
catch (OleDbException e)
{
MessageBox.Show(e.Message) ;
}
con.Close();
}
private void btnupdate_Click( object sender,EventArgs e)
{
updatedata(cmbno.Text,txtname.Text,txtaddress.Text,txtsociety.Text, txtgroup.Text,txtcontact.Text);
}
解决方案
@OriginalGriff:感谢您的提示?位置参数。从未使用 OLDDBCommand
,然后在帮助文件中查找并学习。
It says syntax error but my piece of cording seems to be ok, is there any thing wrong here?
public void updatedata(string EN_NO, string MName, string MAddress, string Society, string Group, string Contact) { OleDbCommand updatenow = new OleDbCommand(); con.Open(); updatenow.Connection = con; updatenow.CommandText = "update Member set MName=?, MAddress=?, Society=?, Group=?, Contact=? where EN_NO=?"; updatenow.Parameters.Add("EN_NO", OleDbType.VarWChar); updatenow.Parameters["EN_NO"].Value = EN_NO; updatenow.Parameters.Add("MName", OleDbType.VarWChar); updatenow.Parameters["MName"].Value = MName; updatenow.Parameters.Add("MAddress", OleDbType.VarWChar); updatenow.Parameters["MAddress"].Value = MAddress; updatenow.Parameters.Add("Society", OleDbType.VarWChar); updatenow.Parameters["Society"].Value = Society; updatenow.Parameters.Add("Group", OleDbType.VarWChar); updatenow.Parameters["Group"].Value = Group; updatenow.Parameters.Add("Contact", OleDbType.VarWChar); updatenow.Parameters["Contact"].Value = Contact; try { int count = updatenow.ExecuteNonQuery(); if (count > 0) { MessageBox.Show("Successfully record updated", "Methodist Church", MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (OleDbException e) { MessageBox.Show(e.Message); } con.Close(); } private void btnupdate_Click(object sender, EventArgs e) { updatedata(cmbno.Text, txtname.Text, txtaddress.Text, txtsociety.Text, txtgroup.Text, txtcontact.Text); }
解决方案
@OriginalGriff: Thanks for the tip about ? positional parameters. Never used OLDDBCommand
before so looked it up in the Help file and learned.
这篇关于尝试更新MS Access时出现语法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!