Click here to Skip to main content
15,895,142 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I get some code here:

<br />
<br />
public class p<br />
{<br />
private static string _ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0; Data Source=.\\IncomeAExpenditure.accdb";<br />
<br />
public static void Execute(string pSqlString)<br />
        {<br />
            OleDbConnection oleDbConn = new OleDbConnection(_ConnectionString);<br />
            oleDbConn.Open();<br />
<br />
            OleDbCommand cmd = new OleDbCommand(pSqlString, oleDbConn);<br />
<br />
            try<br />
            {<br />
                cmd.ExecuteNonQuery();<br />
            }<br />
            catch (Exception ex)<br />
            {<br />
                throw ex;<br />
            }<br />
            finally<br />
            {<br />
                oleDbConn.Close();<br />
            }<br />
        }<br />
}<br />
<br />
string sql = String.Format("INSERT INTO P00001(quyenso, so, no, co, hoten, diachi, lydochi, sotien, sotienbangchu, kemtheo, chungtugoc, ngaythuchi) VALUES('{0}', '{1}', '{2}', '{3}', '{4}', '{5}', '{6}', {7}, '{8}', '{9}', '{10}', '{11}')", txtQuyenSo.Text, txtSo.Text, txtNo.Text, txtCo.Text, txtHoTen.Text, txtDiaChi.Text, txtLyDoChi.Text.Replace("\r\n", String.Empty), txtSoTien.Value, txtSoTienBangChu.Text.Replace("\r\n", String.Empty), txtKemTheo.Text, txtChungTuGoc.Text, txtNgayThuChi.Value.ToString(STR_YyyyMMdd));<br />
          <br />
p.Execute(sql);<br />


This is database access structure
maso (auto number)
ngaythuchi (date/time)
quyenso (text)
so (text)
no (text)
co (text)
hoten (text)
diachi (text)
lydochi (text)
sotien (Number)
sotienbangchu (text)
kemtheo (text)
chungtugoc (text)

When i run execute, i can not insert or update. But i copy sqlstring and run it in access, it is ok.

Help me find error. I can not find this error.
Posted

Hi, I see something wrong. Change no into [no] everything is done.
Thanks everyone.
 
Share this answer
 
Check if your connection string is correct.
 
Share this answer
 
Comments
thuyphuongid 16-Nov-10 1:09am    
I have checked. It is ok. I insert something in other table, it's ok.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900