hi,please help.i want to use msflexgrid as data entry,may i how to save msflexgrid data to SQL database??
thanks!
Printable View
hi,please help.i want to use msflexgrid as data entry,may i how to save msflexgrid data to SQL database??
thanks!
Read up on "SQL INSERT INTO" :)
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:
please help.thanksCode:With MSFlexGrid1
For i = 1 To MSFlexGrid1.rows - 1
'strsql = "INSERT INTO Lat " & _
'" (1,2) VALUES " & _
'" ('" & .TextMatrix(i, 1) & "','" & .TextMatrix(i, 2) & "')"
Can I see the complete code in that Sub?
koolsid:
This is the complete code.
Code: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
Is it a DSN less connection? If yes then try with DSN.
I just modified the string for better readability...
Quote:
strsql = "INSERT INTO Lat (1,2) VALUES ('" & _
.TextMatrix(i, 1) & "','" & _
.TextMatrix(i, 2) & "')"
koolsid:
i try your code ,but the problem still the same.what is DSN less connection??i install the sql database software in my laptop.
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...
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:
The data want to save to the sql database is column1 ,column2 as the photo uploaded.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
please help.thanks!