来自不同查询的Datagridviews [英] Datagridviews from different queries
问题描述
伙计们,我正在尝试使用VB.Net了解一些内容.我是一个绝对的初学者.
Guys, I am trying to understand something using VB.Net. I am a totally, absolute beginner.
我在理解连接和datagridview功能时遇到的问题.我通过从表中简单选择a,b,c建立了数据源.我选择ZoneBinding作为数据源,它可以工作.在thezone.xsd中,我添加一个新查询,从表中选择a,b,c 那里10点. NE ZoneTableAdapter向我展示带有FillBy,Getzone(10)的SQL.好的,但是现在如何在新的datagridview中设置查询?我尝试过
My problem in understanding the connection and the datagridview functionality. I set up a datasource with a simple select a,b,c from table. I choose the ZoneBinding as data source, it works. In thezone.xsd I add a new query select a,b,c from table where a-10. The ne ZoneTableAdapter show me the sql with FillBy, Getzone(10). Ok, but now how can I set up the query in a new datagridview? I tried with
Dim con As New OleDb.OleDbConnection
con.ConnectionString = "Data Source=LDMM;Initial Catalog=Generation;Integrated Security=True"
con.Open()
Dim ds As DataSet = New DataSet
Dim adapter As New OleDb.OleDbDataAdapter
Dim sql As String
sql = "SELECT * from VBV_GenerationZone where zone=12"
adapter.SelectCommand = New OleDb.OleDbCommand(sql, con)
adapter.Fill(ds, sql)
DataGridView2.DataSource = ds.Tables(0)
DataGridView2.Refresh()
但这给了我错误.我重复一遍,我是一个绝对的初学者..谢谢
but it gives me error. I repeat, I am an absolute beginner..thanks
推荐答案
你好,
区域是字符串还是整数?如果是字符串,则需要使用
Is zone a string or integer? If string then you need to use
" SELECT * from VBV_GenerationZone where zone = '12'''
"SELECT * from VBV_GenerationZone where zone='12'"
此外,建议知道错误消息是什么.
Also, it would be advisable to know what the error message is.
最后,您不需要刷新DataGridView.
Lastly you don't need to do a refresh on the DataGridView.
这篇关于来自不同查询的Datagridviews的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!