我如果先要对表中XH字段做一下判断,然后写一个温馨的对话框提示用户XH字段值为0,那字段XH该怎么取出来呢? 大家帮忙看看! 谢谢了,源代码如下,数据库已连接OleDbConnection conn = new OleDbConnection();
        conn.ConnectionString = "Provider = Microsoft.Jet.OleDb.4.0;" + "Data Source =" + Server.MapPath("**.mdb");
sting xh;
if()
{????}
        string updateStr = "update zhuanjia set [xh] = xh-1 where [id] = " + Convert.ToInt32(Request["id"]);        OleDbCommand insCom = new OleDbCommand(updateStr, conn);        conn.Open();        insCom.ExecuteNonQuery();
        conn.Close();

解决方案 »

  1.   

    先通过XH=0条件查询是否有记录,弹出提示框,再修改using(OleDbConnection myConn = new OleDbConnection(""))

    OleDbCommand myCmd = new OleDbCommand("selct * from zhuanjia where [xh]=0", myConn ); 
    try 

     myConn.Open(); 
     OleDbDataReader datareader = myCmd.ExecuteReader(); 
     if(datareader.Read()) 
     {  } 

    catch 
    { } 
    }
      

  2.   

    access的操作
    和连接sql2005差不多,只需要该连接字符串即可.using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Data;
    using System.Data.OleDb;
    using System.Data.SqlClient;namespace TestAccess
    {
        class Program
        {
            static void Main(string[] args)
            {
                #region Access 2007
                Console.WriteLine("Access 2007");
                string strConnection = "Provider=Microsoft.ACE.OLEDB.12.0;";
                strConnection += @"Data Source=C:\Documents and Settings\v-changl\My Documents\Database1.accdb;";
                strConnection += "Persist Security Info=False";
                using (OleDbConnection objConnection = new OleDbConnection(strConnection))
                {
                    objConnection.Open();
                    OleDbDataAdapter myCommandd = new OleDbDataAdapter("select * from Couse", objConnection);
                    DataSet ds = new DataSet();
                    myCommandd.Fill(ds, "couse");
                    DataTable dt = ds.Tables["couse"];
                    Console.WriteLine(dt.Columns[0].ToString());
                    Console.WriteLine(dt.Columns[1].ToString());
                    Console.WriteLine(dt.Columns[2].ToString());                objConnection.Close();            }
                #endregion
    }
    }
    }