How to continue adding new rows?

Results 1 to 2 of 2

Thread: How to continue adding new rows?

  1. #1
    Join Date
    Dec 1969

    Default How to continue adding new rows?

    hiye... code below allow me to add new row to a datatable... what i actually need to do is to continue to add rows when every AddNewRow_OnClick is fired.<BR>but with this code i can only add 1 row at a time.. can anyone show me how to get around this problem? thanks alot people.. <BR>I&#039;ve been stuck with this problem for 2 days. SIGN!<BR><BR><BR> Protected Sub AddNewRow_OnClick(ByVal sender As Object, ByVal e As EventArgs)<BR><BR> Dim myConn As New SqlConnection("server=localhost;uid=sa;pwd=;databa se=northwind")<BR> Dim sqlDA As New SqlDataAdapter("select firstname, lastname, birthdate from employees", myConn)<BR> Dim ds As New DataSet()<BR><BR><BR> sqlDA.Fill(ds, "Employees")<BR><BR> Dim dt As DataTable = ds.Tables(0)<BR><BR> Dim NewDataRow As DataRow = dt.NewRow()<BR> NewDataRow("firstname") = ""<BR> NewDataRow("lastname") = ""<BR> dt.Rows.Add(NewDataRow)<BR><BR> dg.DataSource = ds.Tables("Employees")<BR> dg.DataBind()<BR><BR> End Sub<BR><BR><BR><BR>Simon

  2. #2
    Join Date
    Dec 1969

    Default RE: How to continue adding new rows?

    Hi Simon there is a logical problem to your function.<BR>the first time this function is called it retrieve let say 10 rows , you add 1 empty row. <BR>but the second time you access it is retrieving again 10 rows as you are requerying the database without having updated the database...<BR>If you want to update the database only once every rows have been added then you need to work with the IsPostedBack <BR><BR> Private Sub bindDetails()<BR> Dim AllAvailable As Integer = 0<BR> Dim i As Integer<BR><BR> If Page.IsPostBack Then<BR> ds = CType(Session("ds"), DataSet)<BR> Else<BR> da.Fill(ds)<BR> Session("ds") = ds<BR> End If<BR> &#039;datalist source based on the second select of the StoreProc <BR> dlAvailable.DataSource = ds.Tables(1)<BR> <BR> &#039;dataGrid source based on the Third select of the StoreProc <BR> dgDetail.DataSource = ds.Tables(2)<BR><BR> DataBind()<BR>This way you will be using the modified dataset and not a new one each time the function is called .<BR>Is it answering your question ?

Posting Permissions

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