Results 1 to 2 of 2

Thread: Problem in code

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2006
    Location
    nasik,india
    Posts
    909

    Problem in code

    Code:
      Me.SqlDataAdapter1.SelectCommand.CommandText = "select * from customer"
            MsgBox(Me.DataSet11.Tables(0).Rows.Count)
            Dim d As DataRow = DataSet11.Tables(0).NewRow
            d.Item("cname") = "abc"
            d.Item("address") = "abc"
            DataSet11.Tables(0).Rows.Add(d)
            Me.DataSet11.AcceptChanges()
            Me.SqlDataAdapter1.Update(DataSet11)
            MsgBox(Me.DataSet11.Tables(0).Rows.Count)
    What is the problem in above code ?
    Thia code doesnot give me any error.
    BUt does not add row in my sql database.
    Here id is autonumber field.
    Please tell me.
    Last edited by shukla; May 14th, 2009 at 12:50 AM. Reason: incomplete information
    WHETHER YOU SUCCEED OR FAIL IS NOT AS IMPORTANT AS WHETHER YOU TRIED YOUR BEST

  2. #2
    Fanatic Member manhit45's Avatar
    Join Date
    May 2009
    Location
    Ha noi - Viet Nam
    Posts
    826

    Re: Problem in code

    I think you can modifyagain :

    Quote Originally Posted by shukla View Post
    Code:
      
    Me.SqlDataAdapter1.SelectCommand.CommandText = "select * from customer"
            MsgBox(Me.DataSet11.Tables(0).Rows.Count)
            Dim d As DataRow = DataSet11.Tables(0).NewRow
            d.Item("cname") = "abc"
            d.Item("address") = "abc"
            DataSet11.Tables(0).Rows.Add(d)
            Me.DataSet11.AcceptChanges()
            Me.SqlDataAdapter1.Update(DataSet11)
            MsgBox(Me.DataSet11.Tables(0).Rows.Count)
    .
    to

    Code:
      
    Me.SqlDataAdapter1.SelectCommand.CommandText = "select * from customer"
            MsgBox(Me.DataSet11.Tables(0).Rows.Count)
          dim ndtset as new dataset = Dataset11
      Dim d As DataRow = ndtset.Tables(0).NewRow
           
           ' d.Item("cname") = "abc"
           ' d.Item("address") = "abc"       
     ndtset.Tables(0).Rows.Add(d)
             MsgBox(Me.DataSet11.Tables(0).Rows.Count)
    --***----------***-----

    If i help you please rate me.

    Working with Excel * Working with String * Working with Database * Working with array *

    K51 ĐH BÁCH KHOA HÀ NỘI - Khoa CNTT pro.

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