数据不保存? [英] Data Does Not saved?

查看:125
本文介绍了数据不保存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在MS Access中插入数据

该查询完全执行,所有操作均以coreect方式进行,但是当我打开表时,它不包含输入的数据

代码是

字符串SaveConnString ="Provider = Microsoft.Jet.OLEDB.4.0; Data Source = UI.mdb";
OleDbConnection ConnForSaveTabs =新的OleDbConnection(SaveConnString);
字符串SaveCommand = @插入到选项卡(名称,标题)中的值(""+ txtname.Text +",""+ txtcaption.Text +"'');
OleDbCommand CommandForSave =新的OleDbCommand(SaveCommand,ConnForSaveTabs);
CommandForSave.ExecuteNonQuery();

i want to insert data in MS access

The query execute corectly,everything going in coreect manner but when i open the table it does not contain entered data

the code is

string SaveConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=UI.mdb";
OleDbConnection ConnForSaveTabs = new OleDbConnection(SaveConnString);
string SaveCommand = @" Insert into Tabs (Name,Caption) values(''" + txtname.Text + "'',''" + txtcaption.Text + "'') ";
OleDbCommand CommandForSave = new OleDbCommand(SaveCommand, ConnForSaveTabs);
CommandForSave.ExecuteNonQuery();

推荐答案

暂时忽略此代码如何允许任何人擦除您的数据库,您是否检查了ExecuteNonQuery的返回值?它返回已更改的行数.您是否直接针对您的数据库运行此SQL?我认为没有理由不起作用,但是检查总是很好.

您的数据库仅存储在本地目录中的什么位置?其他变更操作有效吗?数据源中可能缺少路径可能意味着您实际上是在将一个不同的数据库更改为您认为自己的数据库吗?

此外,正如我之前所说,除了不安全之外,在UI层内部硬编码连接字符串和/或在UI层中构建SQL的代码也是不好的代码.我认为您只是在玩,但是您应该在期望任何人为您编写的代码付费之前提高自己的设计技能.
Ignoring for a moment how this code allows anyone to erase your database if they want, have you checked the return value of ExecuteNonQuery ? It returns the number of rows changed. Have you run this SQL against your DB directly ? I see no reason for it not to work, but it''s always good to check.

Where is your DB stored, just in the local directory ? Do other change operations work ? Might your lack of a path in your data source mean you''re actually changing a different DB to the one you think you are ?

In addition, as I''ve said before, apart from being insecure, code that hard codes connection strings inside the UI layer, and/or builds SQL in the UI layer, is bad code. I assume you''re just playing, but you should aim to improve your design skills before expecting anyone to pay for code that you write.


Hi.sharmarun
您的问题既简单又好
您将数据源设置为UI.mdb.
不提供路径,因此首先提供路径,然后设置数据库名称
例如数据源= C:\\ Hello \ UI.mdb";
希望此帮助对您有用
请发送您对这个答案的评论
Hi.sharmarun
Your problem is easy and good
you set a data source=UI.mdb.
Not give a path so first give a path and after set database name
e.g "data source=C:\\Hello\UI.mdb";
I Hope This Help is usefull for you
please send your comment for this answer


这篇关于数据不保存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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