如何从数据库或数据集中检索值 [英] How to Retrieve value from a database or dataset

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

问题描述

我想根据插入ID文本框中的值从我的表中检索信息,并用适当的值填充其余文本框.

Hi i want to retrieve information from my table based on the value inserted in the ID text-box and populate the rest text-box with their appropriate value. how do i go about that.

推荐答案

您需要学习ADO.net的概念.从这里开始:

为初学者使用ADO.NET [
you need the learn the concepts of ADO.net. Start from here:

Using ADO.NET for beginners[^]

hope it helps :)


Uday P.Singh 给出的文章链接对于学习ADO.NET很有帮助.
现在,如果您已经填充了DataSetDataTables ,则要检索与TextBox 中输入的ID对应的DataRow ,可以使用以下代码.
The article link given by Uday P.Singh is good for learning about ADO.NET.
Now, if you have already populated the DataTables of your DataSet, then to retrieve a DataRow corresponding to the ID entered in a TextBox the following code can be used.
//Assuming Employees is the DataTable, EmployeeID, Name and Address as columns of this table
//If the EmployeeID is the primary key in the table, the Find method
//of DataRowCollection returned by Rows property of DataTable can be used
DataRow row = Employees.Rows.Find(TextBoxID.Text);
if (row != null){
    TextBoxName.Text = (string)row["Name"];
    TextBoxAddress.Text = (string)row["Address"];
}
//If the EmployeeID is not the primary key in the table, then Select method
//of DataTable can be used, which returns an array of DataRows matching
//the filter expression given as the first parameter.
DataRow[] rows = Employees.Select(string.Format("EmployeeID='{0}'",
                    TextBoxID.Text),"",DataViewRowState.CurrentRows);
if (rows.Length > 0){
    TextBoxName.Text = (string)rows[0]["Name"];
    TextBoxAddress.Text = (string)rows[0]["Address"];
}


亲爱的..

使用SQLDATAREADER检索数据....
Dear..

USE SQLDATAREADER to retrive data....


这篇关于如何从数据库或数据集中检索值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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