CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 11 of 11
  1. #1
    Join Date
    Dec 2007
    Posts
    42

    save msflexgrid data to sql database

    hi,please help.i want to use msflexgrid as data entry,may i how to save msflexgrid data to SQL database??

    thanks!

  2. #2
    Join Date
    Apr 2009
    Posts
    394

    Re: save msflexgrid data to sql database

    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

  3. #3
    Join Date
    Dec 2007
    Posts
    42

    Re: save msflexgrid data to sql database

    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) & "')"
    Attached Images Attached Images
    Last edited by monchichi2; May 27th, 2010 at 04:23 AM.

  4. #4
    Join Date
    Apr 2009
    Posts
    394

    Re: save msflexgrid data to sql database

    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

  5. #5
    Join Date
    May 2010
    Posts
    12

    Re: save msflexgrid data to sql database

    Some times you need to provide the TableName Fully Qualified.

    INSERT INTO TABLEOWNER.TABLENAME ....

  6. #6
    Join Date
    Dec 2007
    Posts
    42

    Re: save msflexgrid data to sql database

    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 isata.


    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!
    Attached Images Attached Images
    • File Type: jpg 2.jpg (18.3 KB, 3635 views)
    • File Type: jpg 3.jpg (4.3 KB, 3617 views)

  7. #7
    Join Date
    Apr 2009
    Posts
    394

    Re: save msflexgrid data to sql database

    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

  8. #8
    Join Date
    Dec 2007
    Posts
    42

    Re: save msflexgrid data to sql database

    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!
    Attached Images Attached Images
    • File Type: jpg 1.jpg (4.9 KB, 3608 views)
    • File Type: jpg 2.jpg (3.9 KB, 3607 views)

  9. #9
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: save msflexgrid data to sql database

    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?
    Always use [code][/code] tags when posting code.

  10. #10
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: save msflexgrid data to sql database

    Don't use DATA as a field name. Call it something meaningful, and not RESERVED.
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  11. #11
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: save msflexgrid data to sql database

    Agreed and also is wise to avoid spaces in field names
    Always use [code][/code] tags when posting code.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured