How to continue adding new rows?

nolimit

New Member
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'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=;database=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>SimonHi 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> 'datalist source based on the second select of the StoreProc <BR> dlAvailable.DataSource = ds.Tables(1)<BR> <BR> '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 ?
 
Back
Top