CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Oct 2011
    Posts
    1

    Msflexgrid to msaccess db

    Can you please help me with dis code?
    I want to save record in the database by inputing data in the MSFlexgrid ..
    Also it can accept null values..

    Private Sub MSFlexGrid1_KeyPress(KeyAscii As Integer)

    Select Case KeyAscii

    Case Is = 8

    If MSFlexGrid1.Text <> "" Then MSFlexGrid1.Text = Mid(MSFlexGrid1.Text, 1, Len(MSFlexGrid1.Text) - 1)
    Case Else
    MSFlexGrid1.Text = MSFlexGrid1.Text & Chr(KeyAscii)
    End Select

    End Sub

    Private Sub cmdOk_Click()
    For i = 2 To MSFlexGrid1.Rows - 1
    For j = 2 To MSFlexGrid1.Cols - 1

    strSQL = "SELECT * from tblGrades where enroll_ID = " & CInt(MSFlexGrid1.TextMatrix(MSFlexGrid1.Row, 0))
    Set recSet = New ADODB.Recordset
    With recSet
    .Open strSQL, Conn, adOpenKeyset, adLockOptimistic
    .AddNew
    Select Case j
    Case Is = 1
    !prelim_grade = ifIsNull(MSFlexGrid1.TextMatrix(i, j))
    Case Is = 2
    !midterm_grade = ifIsNull(MSFlexGrid1.TextMatrix(i, j))
    Case Is = 3
    !prefinal_grade = ifIsNull(MSFlexGrid1.TextMatrix(i, j))
    Case Is = 4
    !final_grade = ifIsNull(MSFlexGrid1.TextMatrix(i, j))
    Case Is = 5
    !gwa_grade = ifIsNull(MSFlexGrid1.TextMatrix(i, j))


    End Select
    .Update
    .Close
    End With
    Next
    Next
    End Sub
    Attached Images Attached Images  

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

    Re: Msflexgrid to msaccess db

    So what is the problem you are having?
    Always use [code][/code] tags when posting code.

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

    Re: Msflexgrid to msaccess db

    You are hitting the DB for each cell in the grid. You'd be gone fast nowadays, or run up thousands in time-sharing costs (for no reason) extra.

    Explain exactly what you are trying to do, and we can suggest a better way
    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!

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

    Re: Msflexgrid to msaccess db

    I did not notice that db call was inside the nested loop. Not only is it hitting the db way to much but it is creating a new record for every cell in the grid.
    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