Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 2005 > Visual Basic 2005 Basics
|
Visual Basic 2005 Basics If you are new to Visual Basic programming with version 2005, this is the place to start your questions. For questions about the book: Beginning Visual Basic 2005 by Thearon Willis and Bryan Newsome, ISBN: 0-7645-7401-9 please, use this forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Visual Basic 2005 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 16th, 2007, 06:16 AM
Authorized User
 
Join Date: May 2007
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to jazzydonald
Default Problem updating data from a datagrid

I have a data grid that displays data from the DB. Noe i want the user to be able update data in the datadrid cell and update the records.How do i do that? NB: the update should only update the cells whose content has change.
here is my code that displays data in the grid


Private Sub PopulateGrid()
        Dim ObjConn As New SqlConnection("server=(local);database=NHIF;Integr ated security=true")
        Dim objDataAdapter As New SqlDataAdapter("select * from members", ObjConn)
        'Try

        objDataAdapter.SelectCommand = New SqlCommand
        objDataAdapter.SelectCommand.Connection = ObjConn
        objDataAdapter.SelectCommand.CommandText = "select DFname,DLname,Gender,MembershipNo,IssuedDate,Typeo fCard,BirthDate from currentID where CHECKNO='" & Trim(txtCheckNo.Text) & "'"
        objDataAdapter.SelectCommand.CommandType = CommandType.Text
        ObjConn.Open()

        objDataAdapter.Fill(objDataset, "currentID")
        ObjConn.Close()

        DataGridView1.DataSource = objDataset
        DataGridView1.DataMember = "currentID"

        ' Catch
        'MessageBox.Show(Err.Description)

        'End Try

        objDataAdapter = Nothing
        ObjConn = Nothing

    End Sub

Also i have a number of textbox control(about 10) that displays data from the db. I want to allow users to update records in the textbox. Currently it works fine but what i wanted to do is to just update the textbox whose data has change and not all of them where they have changed or not. how do i do that? here is the code that currently update some of the data from the textbox




    Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdate.Click
        ' On Error Resume Next
        Dim objCommand As SqlCommand = New SqlCommand()
        'Dim objconn As New SqlCommand
        Dim ObjConn As New SqlConnection("server=(local);database=NHIF;Integr ated security=true")
        Dim objDataAdapter As New SqlDataAdapter("select * from members", ObjConn)
        'Dim objDataView As DataView()

        objDataView = New DataView(objDataset.Tables("members"))
        objCommand.Connection = ObjConn
        objCommand.CommandText = "UPDATE MEMBERS SET Status= @Status, BirthDT= @BirthDT where CheckNo=@Checkno"
        objCommand.CommandType = CommandType.Text
        objCommand.Parameters.AddWithValue("@Status", cboStatus.Text)
        objCommand.Parameters.AddWithValue("@BirthDT", txtBIRTHDT.Text)
        objCommand.Parameters.AddWithValue("@CheckNo", BindingContext(objDataView).Current("CheckNo"))
        'objCommand.Parameters.AddWithValue("@CheckNo", txtCheckNo.Text)
        ObjConn.Open()
        objCommand.ExecuteNonQuery()
        FillDataSetAndView()
        BindControls()

       MessageBox.Show("Records Updated")
    End Sub






Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem updating a DataGrid RichardP ASP.NET 1.0 and 1.1 Professional 3 February 28th, 2006 11:42 AM
Problem getting updating Database from Datagrid RichardP ASP.NET 1.0 and 1.1 Basics 0 February 17th, 2006 07:55 AM
problem updating using datagrid bananaking ASP.NET 1.0 and 1.1 Basics 7 May 13th, 2005 07:32 AM
problem in updating datagrid noor ASP.NET 1.0 and 1.1 Basics 1 April 26th, 2005 03:10 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.