Public Function Readtime()
ks = " " ks = TextBox1.Text + "-" + TextBox2.Text + "-" + TextBox3.Text + " " + TextBox4.Text + ":" + TextBox5.Text + ":" + TextBox11.Text '查询开始时间 js = " " js = TextBox6.Text + "-" + TextBox7.Text + "-" + TextBox8.Text + " " + TextBox9.Text + ":" + TextBox10.Text + ":" + TextBox12.Text '查询结束时间 End Function
Public Function OpenDB() As Short Readtime() Dim SQLstr As String '定义查询语句 SQLstr = "SELECT 序号, 时间, 室外温度, 一次供水压力, 一次回水压力, 二次供水压力, 二次回水压力, 一次供水温度, 一次回水温度, 二次供水温度, 二次回水" & _ "温度 FROM Station1 where intime >=' " + ks + "' and intime <='" + js + "'" 'Console.Write(SQLstr)
'设置查询语句,其中*号表示表单中所有的列 Dim ADOcmd As SqlCommand '定义一个SqlCommand对象
Adapter = New SqlDataAdapter(SQLstr, "Data Source=localhost;Integrated Security=SSPI;Initial Catalog=opc")
'获取表单并设置了数据库引擎 Try Adapter.Fill(Ds, "station1")
Catch mye As Exception Console.WriteLine("why?" + mye.Message()) End Try '取得表中所有数据 myTable = Ds.Tables.Item(0) '用数据集中的数据填充表单 Me.DataGrid1.DataSource = Ds.Tables.Item(0).DefaultView '设置数据表格的数据源
End Function
Private Sub Button1_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles Button1.Click OpenDB() '打开数据库并显示在数据表中 Readtime() '读取查询条件 Me.Button1.Enabled = True End Sub Private Sub Button2_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles Button2.Click Me.Close() End '退出程序 End Sub
End Class