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

    Have an "INSERT" option in GridView...??

    Hi all...

    I work with VS2005 with .NET 2.0 and with Access DB. I have created a website using "ASP.NET AJAX-Enabled Web Site" with language C#.

    This may be a stupid question and please bear with me... Is it possible to have an "INSERT" option in GridView...?? Let me explain the scenario:

    I need to display a blank data row for the database file I have selected, where-in I need to start entering data with certain fields (columns) having pre-defined data.

    I need your experts' guidance on how to go about doing this?

    Thank you.
    Thank you for your support.

    Best regards,
    Lax

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

    Re: Have an "INSERT" option in GridView...??

    If the table is bound to the grid, you add a row. Otherwise, move lower rows down by 1 and erase the current line fields.
    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!

  3. #3
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,283

    Re: Have an "INSERT" option in GridView...??

    Just remember, you may have to update the tables connected to the DGV. Because, when you type new stuff in, it may not be saved, and when the application is run again, it won't display the entered values.

    I don't know how you have connected, but the following just shows a small example on upodating the Database with the new values entered in the DGV, when the Button is clicked :
    Code:
    Public Class Form1
        Dim con As OleDb.OleDbConnection
        Dim db As OleDb.OleDbDataAdapter
        Dim dset As New DataSet
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            con = New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\Students.mdb")
            db = New OleDb.OleDbDataAdapter("select * from Details", con)
    
            dset.Clear()
            db.Fill(dset, "Details")
            DataGridView1.DataSource = dset.Tables("Details")
    
        End Sub
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim cm As OleDb.OleDbCommandBuilder = New OleDb.OleDbCommandBuilder(db)
            db.Update(dset, "Details")
        End Sub
    
    
    End Class

  4. #4
    Join Date
    Oct 2006
    Posts
    449

    Re: Have an "INSERT" option in GridView...??

    Hi Hannes...!

    Hope you remember me... I was in this forum couple o years back and now a back after my project and am still learning...!

    Thank you for the reply. But I work on a web-based project and I work on Visual Web Developer 2005 Express Edition and my backend is Access DB. Now how do I implement this code? Please bear with me. Thank you.
    Thank you for your support.

    Best regards,
    Lax

  5. #5
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,283

    Re: Have an "INSERT" option in GridView...??

    Of course I rememebr you, it's great to have you back here, and that you are still learning!

    Is your DGV in your Visual Web Developer 2005 Express Edition project ¿

  6. #6
    Join Date
    Oct 2006
    Posts
    449

    Re: Have an "INSERT" option in GridView...??

    Hi Hannes, Thank you for remembering me. This is a sample project and am testing out few things. Yes... I was using GridView in VS2005. As I had mentioned earlier... The scenario is: I need to display a blank data row for the database file I have selected, where-in I need to start entering data with certain fields (columns) having pre-defined data.
    Thank you for your support.

    Best regards,
    Lax

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

    Re: Have an "INSERT" option in GridView...??

    That IS an Access DB:

    Code:
        con = New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\Students.mdb")

    You have to do what I said before. Read the last post of mine so I don't have to type it again.
    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!

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