使用asp.net从数据库表中检索值 [英] Retrive Values from database table using asp.net

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

问题描述

我有两个桌子
一个emp和另一个dep
我想检索一个emp表值和另一个dept表值
在文本框中.
我如何在asp.net中做到这一点.

I have two tables
one emp and another dep
i want retrive one emp table values and another dept table values
in textboxes.
how can i do it in asp.net.

推荐答案

好的参考资料: ^ ]
Nice reference at: http://www.4guysfromrolla.com/articles/022206-1.aspx[^]


尝试查询Select column1, column2 from table.


基本内容,搜索.这是一个简单的例子...

Basic stuff, search. Here''s a simple example tho...

string commandText = "SELECT column1, column2 FROM MyTable Where Column1 IS NOT NULL"
var results = new DataSet();

var connectionString = ConfigurationManager
    .ConnectionStrings["MyConnectionStringName"].ConnectionString;

using (var connection = new SqlConnection(connectionString))
{
    connection.Open();
    using (var command = new SqlCommand(commandText, connection))
    {
        var adapter = new SqlDataAdapter(command);
        adapter.Fill(results);
    }
}

if (results.Tables.Count > 0)
{
    var firstTable = results.Tables[0];
    
    // Do something with the results
    foreach(var row in firstTable.Rows)
    {
        // do something??!
    }
}


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

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