错误代码请高手赐教

lihonst 2010-07-28 12:17:14
public partial class Form1 : Form
{
private string conStr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\\lixin\\1.mdb";
OleDbConnection con = null;

public Form1()
{
InitializeComponent();
}

public void Connetion()
{
try
{
con = new OleDbConnection(conStr);
con.Open();
}
catch (Exception e)
{
MessageBox.Show(e.Message);
}
}

public void Funtion(string sqlStr)
{
try
{
OleDbCommand comm = new OleDbCommand(sqlStr, con);
comm.ExecuteNonQuery();
}
catch (Exception e)
{
MessageBox.Show(e.Message);
}
}

private void Close()
{
try
{
con.Close();
}
catch (Exception e)
{
MessageBox.Show(e.Message);
}
}
private void button1_Click(object sender, EventArgs e)
{
string sqlStr = "update Me set Me.Sex=Student.sex from Student ,Me where Me.Name=Student.Name";
Connetion();
Funtion(sqlStr);
Close();

}
这是全部代码,为啥那个SQL语句执行时总是错呢,请各位高手帮帮我!它总是提示语法错误,操作符丢失!谢谢了!
...全文
55 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
Zhanlixin 2010-07-28
  • 打赏
  • 举报
回复
Access的SQL语句和SQL Server不一样:
应改为:
string sqlStr = "update Me a ,Student b set a.Sex=b.sex where a.Name=b.Name";
jointan 2010-07-28
  • 打赏
  • 举报
回复
试试
update Me set Me.Sex=Student.sex from Student inner join Me on Me.Name=Student.Name
要保证Student的Name唯一
jointan 2010-07-28
  • 打赏
  • 举报
回复
试试
update Me set Me.Sex=Student.sex from Student inner join Me on Me.Name=Student.Name
要保证Student的Name唯一
slmintg 2010-07-28
  • 打赏
  • 举报
回复
string sqlStr = "update Me set Me.Sex=Student.sex from Student ,Me where Me.Name=Student.Name";
你的Student从何而来
lihonst 2010-07-28
  • 打赏
  • 举报
回复
谢谢!终于解决了!
烈火蜓蜻 2010-07-28
  • 打赏
  • 举报
回复
--把
string sqlStr = "update Me set Me.Sex=Student.sex from Student ,Me where Me.Name=Student.Name";

--改成

string sqlStr = "UPDATE Me SET Me.Sex=Student.sex FROM Student WHERE Me.Name=Student.Name";

110,561

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧