koolsid:
hi,currently i'm able to insert data to sql database.but have error message appear.if i insert 1 column data to sql database is work fine.after that i try to write second row data us the code below.when i try to insert data to sql
server have this error message appear .
this is the current code:
Code:
With MSFlexGrid1
For i = 1 To MSFlexGrid1.rows - 1
'strsql = "INSERT INTO Lat " & _
'" (1,2) VALUES " & _
'" ('" & .TextMatrix(i, 1) & "','" & .TextMatrix(i, 2) & "')"
Private Sub Command2_Click()
Dim i As Long
Dim strsql As String
Dim conDataConnection As Connection
Dim rs As ADODB.Recordset
Dim conn As New ADODB.Connection
Set conn = New ADODB.Connection
Set conDataConnection = New Connection
conn.ConnectionString = "driver={SQL Server};Server=GRACEKUO;Uid=sa;pwd=sa;database=LAT"
conn.Open
With MSFlexGrid1
For i = 1 To MSFlexGrid1.rows - 1
strsql = "INSERT INTO Lat " & _
" (1,2) VALUES " & _
" ('" & .TextMatrix(i, 1) & "','" & .TextMatrix(i, 2) & "')"
Debug.Print strsql
conn.Execute (strsql)
Next
conn.Close
Set conn = Nothing
End With
End Sub
DSN-less is defining the ODBC driver, database, userid, password, etc. all in the connection string. Where as DSN is having all that same information pre-defined. You define it in Control Panel->Admin Tools->Data Sources (ODBC).
Let me go through your code once again if I am missing something...
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread "Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
koolsid:
hi,i already try the method as your guide,but the problem still the same.The data from msflexgrid save to sql database name is:Lat and tablename:Lat ,field name to save the data is call Data.
i have change to the code as below:
Code:
With MSFlexGrid1
For i = 1 To MSFlexGrid1.Cols - 1
strsql = "INSERT INTO Lat (Data) VALUES ('" & _
.TextMatrix(i, 1) & "','" & _
.TextMatrix(i, 2) & "')"
Debug.Print strsql
conn.Execute (strsql)
Next
conn.Close
Set conn = Nothing
The data want to save to the sql database is column1 ,column2 as the photo uploaded.
please help.thanks!
Last edited by gracehskuo; Jun 1st, 2010 at 03:38 AM.