Hur uppdaterar man en datagrid i en form från en class som kör sql fråganHur uppdaterar man en datagrid i en form från en class som kör sql frågan
här är classen, Vet att jag har gjort fel och har markerat området med
*************
jag vill ha in det i en datagrid i formen !
Hur ?
Imports System
Imports System.IO
Imports System.Threading
Imports System.Text
Imports System.Data
'Imports System.Data.SqlTypes
Imports System.Data.SqlClient
'Imports System.Data.SqlClient.SqlCommand
Imports System.Data.SqlClient.SqlConnection
'Imports System.Data.SqlClient.SqlParameter
Imports System.Data.SqlClient.SqlTransaction
Public Class DTG1_1M
Inherits trgrund
Private MSDATASET As New DataSet
Private MPDAD As SqlDataAdapter
Private WithEvents MTBL As DataTable
Private sokva As String
Private namna As String
Public Property sokv() As String
Get
Return sokva
End Get
Set(ByVal Value As String)
sokva = Value
End Set
End Property
Public Property namn() As String
Get
Return namna
End Get
Set(ByVal Value As String)
namna = Value
End Set
End Property
Public Function tsokv() As String
Return sokva & namna
End Function
Public Function dataingr() As String
Return inkorning()
End Function
Public Function inkorning() As String
End Function
Public Sub New()
'Dim rummel As New TR1
Dim Sm1_2 As New ThreadStart(AddressOf smin1)
AVTG1 = False
TG1 = New Thread(Sm1_2)
TG1.IsBackground = True
TG1.Start()
' rummel.DataGrid1.Show()
End Sub
Private Sub smin1()
**********************************
Dim rummel As New TR1
Dim cn As New SqlConnection
cn.ConnectionString = "Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=Trading;Data Source=SMO;Packet Size=4096;Workstation ID=SMO"
Dim STR As String = "SELECT SIGNAL,S1,S2,S3,S4,S5,S6,OM1,OM2,OM3,OM4,OM5,OM6 FROM TR@EC"
MPDAD = New SqlDataAdapter(STR, cn)
Dim CMDBYLD As New SqlCommandBuilder(MPDAD)
MPDAD.Fill(MSDATASET, "TR@EC")
MTBL = MSDATASET.Tables(0)
rummel.DataGrid1.PreferredColumnWidth = 50
rummel.DataGrid1.DataSource = MTBL
rummel.DataGrid1.Show()
cn.Close()
**********************************
End Sub
End Class