如何在gridview中显示查询结果 [英] how to display the query result in gridview

查看:73
本文介绍了如何在gridview中显示查询结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好

请检查以下代码

Hi all

Please check the below code

If (DateTime.Now = "01/01/2013") Then
               Dim sql00 = "select sum(EL),sum(ML) from attendance where Emp_name = '" + ComboBox1.Text + "'"
               Dim sql000 = sql00 + " SELECT 15+ sum(EL) as el, 14 + sum(ML) as ml from attendance where Emp_name = '" + ComboBox1.Text + "' "
               DataGridView2.Rows.Add(sql000)
           End If


请告诉我代码是否正确,我想将sql000的值显示给现有的gridview ...

请告诉我该怎么做..


Please tell me whether the code is correct or not and i want to display the value of sql000 to a existing gridview...

please tell me how to do it..

推荐答案

只需更新您的查询


just update your query


select sum(EL),sum(ML),15+ sum(EL) as el, 14 + sum(ML) as ml from attendance where Emp_name = '" + ComboBox1.Text + "'"




这是连接到Ms Access中的数据库的代码.

通过OLE DB进行MS Access的连接字符串:
昏暗的连接为OleDbConnection
connection =新的OleDbConnection("Provider = Microsoft.Jet.OLEDB.4.0; Data Source = C:\ NorthWind.mdb; User Id =; Password =;")
connection.Open();

连接到数据库后

将dim da用作新的oledb.oledbdataadapter(您的查询",连接)
将dim ds作为新数据集
da.fill(ds)

现在您可以将数据设置为网格了....

DataGridView1.DataSource = ds
DataGridView1.DataMember =表名"

希望这会有所帮助

请参阅以下内容:

http://www.homeandlearn.co.uk/net/nets12p6.html
http://www.daniweb.com/software-development/vbnet/threads/44695/retrieve-data-by-vb.net [ http://stackoverflow.com/questions/6353889/how- to-retrieve-data-from-database-using-select-query [


Here is the code to connect to the database in Ms Access.

Connection string for MS Access via OLE DB:
Dim connection As OleDbConnection
connection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\NorthWind.mdb;User Id=;Password=;")
connection.Open();

After connecting to the database

dim da as new oledb.oledbdataadapter("your query",connection)
dim ds as new dataset
da.fill(ds)

Now u can set the data to the grid....

DataGridView1.DataSource = ds
DataGridView1.DataMember = "table name"

Hope this helps

Refer these:

http://www.homeandlearn.co.uk/net/nets12p6.html
http://www.daniweb.com/software-development/vbnet/threads/44695/retrieve-data-by-vb.net[^]
http://stackoverflow.com/questions/6353889/how-to-retrieve-data-from-database-using-select-query[^]

mark it if u find it usseful....


这篇关于如何在gridview中显示查询结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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