Access db错误,代码C#,帮我找到错误? [英] Wrong in access db, code C#, help me find error?

查看:65
本文介绍了Access db错误,代码C#,帮我找到错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里得到一些代码:

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 />



这是数据库访问结构
马索(汽车号码)
ngaythuchi(日期/时间)
quyenso(文本)
所以(文字)
否(文字)
co(文字)
变通(文字)
diachi(文本)
lydochi(文字)
sotien(编号)
sotienbangchu(文本)
kemtheo(文本)
chungtugoc(文本)

当我运行执行时,我无法插入或更新.但是我复制了sqlstring并在access中运行它,没关系.

帮我找出错误.我找不到此错误.



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.

推荐答案

您好,我发现有问题.将no更改为[no]一切完成.
谢谢大家.
Hi, I see something wrong. Change no into [no] everything is done.
Thanks everyone.


检查您的连接字符串是否正确.
Check if your connection string is correct.


这篇关于Access db错误,代码C#,帮我找到错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆