MS Access UPDATE QUERY问题

时间:2010-01-19 18:10:02

标签: c# ms-access ado.net

我正在尝试使用此功能从c#ado.net更新我的表。我正在使用更新过程存储prosedure访问db.Everything在MS Access端正常工作。提供参数访问及其更新。但是当我在c#ado.net这边试过没有给出任何错误,但它没有更新。我有这么多工作存储过程,就像这样。

这是我的ado.net端代码;

 public void TakipsizlikGuncelleYeni(int kararNo, int kararYil, int yeniSorNo, int yeniSorYil,int durum)
  {
      con.Open();
      cmd = new OleDbCommand("sp_NewUpdate", con);
      cmd.CommandType = CommandType.StoredProcedure;
      OleDbParameter prmDurum = new OleDbParameter();
      prmDurum.ParameterName = "@durum";
      prmDurum.OleDbType = OleDbType.Integer;
      prmDurum.Value = durum;
      OleDbParameter prmTakipsizlikNo = new OleDbParameter();
      prmTakipsizlikNo.ParameterName = "@takipsizlikno";
      prmTakipsizlikNo.OleDbType = OleDbType.Integer;
      prmTakipsizlikNo.Value = kararNo;
      OleDbParameter prmTakipsizlikYil = new OleDbParameter();
      prmTakipsizlikYil.ParameterName = "@takipsizlikyil";
      prmTakipsizlikYil.OleDbType = OleDbType.Integer;
      prmTakipsizlikYil.Value = kararYil;
      OleDbParameter prmYeniSorYil = new OleDbParameter();
      prmYeniSorYil.ParameterName = "@yenisoryil";
      prmYeniSorYil.OleDbType = OleDbType.Integer;
      prmYeniSorYil.Value = yeniSorYil;
      OleDbParameter prmYeniSorNo = new OleDbParameter();
      prmYeniSorNo.ParameterName = "@yenisorno";
      prmYeniSorNo.OleDbType = OleDbType.Integer;
      prmYeniSorNo.Value = yeniSorNo;
      cmd.Parameters.Add(prmDurum);
      cmd.Parameters.Add(prmTakipsizlikNo);
      cmd.Parameters.Add(prmTakipsizlikYil);
      cmd.Parameters.Add(prmYeniSorNo);
      cmd.Parameters.Add(prmYeniSorYil);



      int sonuc = cmd.ExecuteNonQuery();
      if (sonuc > 0)
          MessageBox.Show("İşlem Tamamlandı", "Kayıt", MessageBoxButtons.OK, MessageBoxIcon.Information);
      con.Close();
  }

和我的访问方存储了prosedure;

UPDATE Takipsizlik SET Durum = [@durum], YeniSorusturmaNo = [@yenisorno], YeniSorYil = [@yenisoryil]
WHERE (((TakipsizlikNo)=[@takipsizlikno]) AND ((TakipsizlikYil)=[@takipsizlikyil]));

我看不到任何错误?为什么这个代码不能更新我的表?

1 个答案:

答案 0 :(得分:1)

Access接收参数为“?” - 它们没有命名 - 只需使用“问号”占位符。

必须按照它们在查询中出现的确切顺序传递它们。

这是OLEDB的限制。

http://www.4guysfromrolla.com/webtech/092601-1.2.shtml