从自动编号中检索数据并显示 [英] Retrieve Data from autonumber and display it

查看:50
本文介绍了从自动编号中检索数据并显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

慧..
我有一个数据库呼叫Student,其中包含所有学生信息以及学生ID.
我创建了一个表单,其中管理员必须插入有关学生的所有数据..
然后在管理员点击保存按钮后,
我想同时显示所有信息以及学生ID(自动编号)..
我尝试过,但是遇到了错误..
这是我的编码.
谁能指导我..

hye..
I have a database call student which consists of all students information and also student id..
i have created a form that admin have to insert all the data about student..
then after admin click a save button,
i want to display all the information also with the student id(autonumber)..
i have try,but got an error..
this is my coding..
can anyone guide me..

OleDbConnection conn = new OleDbConnection("provider=microsoft.jet.oledb.4.0;data source=dbStd.mdb;");
OleDbCommand cmd = new OleDbCommand("SELECT StdId FROM Student WHERE StdId ='{0}'");
conn.Open();

OleDbDataReader dr = null;
dr = cmd.ExecuteReader();

while(dr.Read())
{
textBox1.Text = dr.GetString(0);
}


dr.Close();
conn.Close();

推荐答案

谢谢您的提问,

Thank you for your question,

OleDbConnection conn = new OleDbConnection("provider=microsoft.jet.oledb.4.0;data source=dbStd.mdb;");
OleDbCommand cmd = new OleDbCommand("SELECT StdId FROM Student WHERE StdId =IdHere");
conn.Open();
OleDbDataReader dr = null;

cmd.Connection = conn; //add this line

dr = cmd.ExecuteReader();
while(dr.Read())
{
textBox1.Text = dr.GetString(0);
}

dr.Close();
conn.Close();




谢谢,
Mamun




Thanks,
Mamun


这可能是我很胖,但是什么是
This may be me being very thick, but what is
WHERE StdId =''{0}''

应该实现吗?
我不知道其中有没有SQL语法,您在哪里找到的?


如果要保存数据并立即读回数据,则可能要考虑使用Guid而不是autonumber字段-这样,您可以控制id,而不必查询db来查找具有什么值的数据库.已被分配.

supposed to achieve?
I know of no SQL syntax which includes this, where did you find it?


If you are going to save data and read it back immediately, you might want to consider using a Guid rather than an autonumber field - that way you are in control of the id and do not have to query the db to find out what value has been assigned.


这篇关于从自动编号中检索数据并显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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