none
Boolean準則運算式的資料類型不符合 RRS feed

  • 問題

  • vista

    vs2008

    c#

    access 2003

     

    各位前輩:

     

    我在 ACCESS內有一個欄位CheckState 資料類型為【是/否】,格式為True/False,預設值【0】

    設定為一次只能修改一筆datagridview內的資料

    但我在異動回資料庫時出現錯誤【運算準則式的資料類型不符合

    已經確定錯誤是因為+ "', CheckState = '" + DataGridView1.CurrentRow.Cells["CheckState"].Value  這行

    如果把它註解掉

    資料就可異動回去

     

    請問各位前輩

    關於Boolean的值要如何異動才對???

     

    附上程式下:

    OleDbConnection conn ;

    OleDbCommand cmd;

    DataSet ds;

    string connString,cmdString,nowUserName;

     

    private void updateButton_Click(object sender, EventArgs e)
     {

                try
                {

                //取得目前所在資料行內UserName欄內的值,pk
                nowUserName = DataGridView1.CurrentRow.Cells["UserName"].Value.ToString();

     

                 ds = new DataSet();

     

                string connString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\mytable.mdb;Jet OLEDBBig Smileatabase Password=" + dbPasswordTextBox.Text;


                conn = new OleDbConnection(connString);

                conn.Open();


                    cmdString = "UPDATE mytable SET UserName = '"

                                      + DataGridView1.CurrentRow.Cells["UserName"].Value.ToString()

                                      + "', CheckState = '" + (Boolean)DataGridView1.CurrentRow.Cells["CheckState"].Value.ToString()
                                      + "' WHERE Account = '" + nowUserName + "'";

     

                    cmd = new OleDbCommand(cmdString, conn);
                    cmd.ExecuteNonQuery();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
                finally
                {

                    cmdString = "SELECT * FROM [mytable]";
                    ds = new DataSet();
                    da = new OleDbDataAdapter(cmdString, conn);

                    da.Fill(ds, "mytable");

                    DataGridView1.DataSource = ds.Tables["mytable"];

                    conn.Close();

                }

    }

    2008年7月1日 上午 06:54

解答

所有回覆