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!
The easy answer... Loop through the records of the FG and extract the entered data to put into an insert statement that you can execute via ADO's connection object...
Good Luck
vb5prgrmr:
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:
With MSFlexGrid1
For i = 1 To MSFlexGrid1.rows - 1
'strsql = "INSERT INTO Lat " & _
'" (1,2) VALUES " & _
'" ('" & .TextMatrix(i, 1) & "','" & .TextMatrix(i, 2) & "')"
Lat should be a table name, if it is a field name then your problem. A correctly formatted insert statement looks like this...
INSERT INTO tablename(fieldname1,fieldname2) VALUES('" & textvalue & "'," & numericvalue & ")"
Good Luck
Some times you need to provide the TableName Fully Qualified.
INSERT INTO TABLEOWNER.TABLENAME ....
vb5prgrmr,
hi,i try the method as you guide,but still have error message appear.
The data from msflexgrid save to sql database name is:Lat and tablename:Lat ,field name to save the data is:Data.
current 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!
Okay, in your values arguement you are specifing two fields but in your table(fields) arguement, you are only specifing one field and that field uses a reserved keyword!
Now, if both of those values are to go into one field then...
Code:...VALUES ('" & .TextMatrix(i, 1) & "," & .TextMatrix(i, 2) & "')"
Good Luck
vb5prgrmr:
hi,thanks is work.but then the data saved to database field is not combined together.
for example: column 1 and column 2 from msflexgrid :
column 1 :1 ,2
column 2:21,22
so the the data saved to database field become 4 line data: 1,2,21,22
i have upload the photo.please help.thanks!
It would help if you were to tell us what it is that you are trying to do.
You only have one field but 2 columns and those columns are text. The logical way they would be combined is by concantonation as was done in the code given to you above.
What result are you trying to get here?
Don't use DATA as a field name. Call it something meaningful, and not RESERVED.
Agreed and also is wise to avoid spaces in field names