string strconn = " provider=Microsoft.Jet.OLEDB.4.0;Data Source=hotel.mdb" ; 
OleDbConnection  myconn = new OleDbConnection (strconn) ;
string strHY="select 会员号 from 客户信息表 where 房号='";
strHY+=comboBox1.Text+"'";
                DataSet dsHY=new DataSet();
myconn.Open();
OleDbDataAdapter daHY=new OleDbDataAdapter(strHY,myconn);
                daHY.Fill(dsHY,"客户信息表");
string HY=dsHY.Tables["客户信息表"].Rows[0]["会员号"].ToString();

string huiyuanbiao="select 住店次数,消费金额 from 会员表 where 会员号='";
huiyuanbiao+=HY+"'";
OleDbDataAdapter DAHY=new OleDbDataAdapter(huiyuanbiao,myconn);
DAHY.Fill(dsHY,"会员表");
int cishu1=Convert.ToInt32(dsHY.Tables["会员表"].Rows[0]["住店次数"]);
int jinE1=Convert.ToInt32(dsHY.Tables["会员表"].Rows[0]["消费金额"]);
int cishu=cishu1+1;
int jinE=jinE1+Convert.ToInt32(textBox7.Text); if(HY=="")
{
MessageBox.Show("非会员");
}
else
{
string InsertHuiyuan="UPDATE 会员表 set 住店次数=";
InsertHuiyuan+=cishu+"and 消费金额=";
InsertHuiyuan+=jinE+" where 会员号='";
InsertHuiyuan+=HY+"'";
OleDbCommand inst2=new OleDbCommand( InsertHuiyuan,myconn);
inst2.ExecuteNonQuery () ; 
}
myconn.Close();
上面是代码,为什么数据表总是更新不了呢?
调试没错误,就是不更新.
谢谢了?

解决方案 »

  1.   

    //and前面少了一个空格
    InsertHuiyuan+=cishu+" and 消费金额=";
      

  2.   

    //更正
    //update中的set中的条件用逗号分隔
    InsertHuiyuan+=cishu+" , 消费金额=";
      

  3.   

    string strconn = "provider=Microsoft.Jet.OLEDB.4.0;Data Source=hotel.mdb" ; 
    OleDbConnection  myconn = new OleDbConnection (strconn) ;
    string strHY="select 会员号 from 客户信息表 where 房号='";
    strHY+=comboBox1.Text+"'";
    DataSet dsHY=new DataSet();
    myconn.Open();
    OleDbDataAdapter daHY=new OleDbDataAdapter(strHY,myconn);
    daHY.Fill(dsHY,"客户信息表");
    string HY=dsHY.Tables["客户信息表"].Rows[0]["会员号"].ToString();

    string huiyuanbiao="select 住店次数,消费金额 from 会员表 where 会员号='";
    huiyuanbiao+=HY+"'";
    OleDbDataAdapter DAHY=new OleDbDataAdapter(huiyuanbiao,myconn);
    DAHY.Fill(dsHY,"会员表");
    int cishu1=Convert.ToInt32(dsHY.Tables["会员表"].Rows[0]["住店次数"]);
    int jinE1=Convert.ToInt32(dsHY.Tables["会员表"].Rows[0]["消费金额"]);
    int cishu=cishu1+1;
    int jinE=jinE1+Convert.ToInt32(textBox7.Text); if(HY=="")
    {
    MessageBox.Show("非会员");
    }
    else
    {
    string InsertHuiyuan="UPDATE 会员表 set 住店次数= ";
    InsertHuiyuan+=cishu+" , 消费金额=";
    InsertHuiyuan+=jinE+" where 会员号='";
    InsertHuiyuan+=HY+"'";
    OleDbCommand inst2=new OleDbCommand( InsertHuiyuan,myconn);
    inst2.ExecuteNonQuery () ; 
    }
    myconn.Close();