Home > Software engineering >  Urgent help - how the SQL query result shows in DataGridView1
Urgent help - how the SQL query result shows in DataGridView1

Time:10-14

Database sql2012
Connection function can be normal connection


Sub connect ()
On Error GoTo err
Dim strSQLServerName strSQLDBUserName, strSQLDBPassword strSQLDBName, Cnnstr As String
StrSQLServerName="192.168. 7.0.x.x" 'SQL Server Server name
StrSQLDBUserName="sdddd45a" 'SQL Server database user name
StrSQLDBPassword="12648553" 'SQL Server database password
StrSQLDBName="xxxworxxxd" 'database of SQL Server database instance name (product)
Cnnstr="PROVIDER=MSDASQL; SQL SERVER DRIVER={}; Server="& amp; StrSQLServerName & amp; "; The Database="& amp; StrSQLDBName & amp; "; UID="& amp; StrSQLDBUserName & amp; "; The PWD="& amp; StrSQLDBPassword & amp; ";"

Conn=New ADODB. Connection
Conn. ConnectionTimeout=0
Conn.Com mandTimeout=100000000
Conn. Open (Cnnstr)

Err:
Sleep (3000)
End Sub

Sub rsOpendele (ByVal SQL As String)
On Error GoTo err
Rs=New ADODB. You
Rs. CursorLocation=ADODB. CursorLocationEnum. AdUseClient
Rs. The Open (SQL, conn, ADODB. CursorTypeEnum. AdOpenKeyset, ADODB. LockTypeEnum. AdLockPessimistic) 'adLockOptimistic
The Exit Sub

Err:
Sleep (3000)
End Sub


Sub rsOpen (ByVal SQL As String)
On Error GoTo err
Rs=New ADODB. You
Rs. CursorLocation=ADODB. CursorLocationEnum. AdUseClient
'rs. Open (SQL, conn, ADODB. CursorTypeEnum. AdOpenKeyset, ADODB. LockTypeEnum. AdLockOptimistic)
Rs. The Open (SQL, conn, ADODB. CursorTypeEnum. AdOpenStatic, ADODB. LockTypeEnum. AdLockOptimistic)

The Exit Sub
Err:
Sleep (3000)
End Sub
Using rs. Fields (" field name "). The Value can be normal to obtain rsopen (SQL) of the data,

Now would like to ask how to
SQL="select * from WXXX"
Rsopen (SQL)
Or
Conn. Excute (SQL)
According to the results to the
Vb 2008 DataGridView1,

Thank you very much!


CodePudding user response:

Dim ds as new dataset
Using da as new SqlDataAdapter (" select * from XXX ", cn) or CNSTR (cn)
'Da. The fill (ds)
End using

Datagridview1. The datasource=ds. Table (0)

CodePudding user response:

If there is no data binding, can also manually ADD. Refer to below me,
Localtable=localds. Tables. The Item (0)
Localrow=localtable. Rows. The Item (I)
DataGridView1. Rows. The Add ()
DataGridView1. Rows (I). HeaderCell. Value=https://bbs.csdn.net/topics/(I + 1). The ToString
DataGridView1. Rows. The Item (I) Cells (0). The Value=(0)
https://bbs.csdn.net/topics/localrow.Item
Remember to add the FOR NXET statements,
  • Related