注册 登录
编程论坛 VB.NET论坛

求数据库查询写数据

w314421717 发布于 2013-10-14 17:16, 725 次点击
Private Sub setE()
        Dim ccy As New SqlClient.SqlConnection
        Dim str As String = "server=192.168.186.1;uid=dba;pwd=Password;database=top"
        Dim cmd2 As New SqlClient.SqlCommand
        Dim tb2 As New DataTable
        Dim ada1 As New SqlClient.SqlDataAdapter
        ccy = New System.Data.SqlClient.SqlConnection(str)
        ccy.Open()
        Dim strsql2 = "SELECT BS,D,V,ZL,HH,(case when substring(D,1,1)='S' then JE*1 else JE*-1 end) as money,(case when substring(D,1,1)='S' then SL*1 else SL*-1 end) as SL,THBS,txdate FROM  typ"
         = strsql2
        cmd2.Connection = ccy
        ada1.SelectCommand = cmd2
        tb2.Clear()
        ada1.Fill(tb2)
        DataGridView1.DataSource = tb2
        DataGridView1.Refresh()
        DataGridView1.Visible = True
        Dim cmd3 As New SqlClient.SqlCommand
        Dim tb3 As New DataTable
        Dim ada12 As New SqlClient.SqlDataAdapter
        Dim strsql3 = "SELECT BS,D,V,ZL,HH,(case when substring(D,1,1)='S' then JE*1 else JE*-1 end) as money,(case when substring(D,1,1)='S' then SL*1 else SL*-1 end) as SL,THBS,txdate FROM typ"
         = strsql3
        cmd3.Connection = ccy
        ada12.SelectCommand = cmd3
        tb3.Clear()
        ada12.Fill(tb3)
        DataGridView2.DataSource = tb3
        DataGridView2.Refresh()
        DataGridView2.Visible = True
        ccy.Close()
    End Sub
我想将这2个查询结果写到192.168.186.2数据库topcs  DataGridView 写到数据库 或者查询值直接写入,本人不太懂这其中奥妙~!
2 回复
#2
tlliqi2013-10-14 18:35
顶一下
1