R
RN1
A Form has a few fields & a Repeater. When the Submit button is
clicked, I want 2 things:
- the record is inserted in a database
- the Repeater should display the just inserted record (along with the
other records).
I could implement the first but not the second. This is how I tried it
(this is the OnClick event function of the Button):
-----------------------
Dim dSet As DataSet
Dim sqlCmd As SqlCommand
Dim sqlConn As SqlConnection
Dim sqlDapter As SqlDataAdapter
sqlConn = New SqlConnection("......")
sqlDapter = New SqlDataAdapter
sqlCmd = New SqlCommand("SELECT * FROM ETS ORDER BY EID", sqlConn)
sqlDapter.SelectCommand = sqlCmd
dSet = New DataSet
sqlDapter.Fill(dSet, "ETS")
sqlCmd = New SqlCommand("INSERT INTO ETS (SDateTime, EDateTime, Count,
Description) VALUES (@SDateTime, @EDateTime, @Count, @Description)",
sqlConn)
With sqlCmd
.Parameters.Add("@SDateTime", SqlDbType.DateTime).Value =
CDate(dtStart)
.Parameters.Add("@EDatetIme", SqlDbType.DateTime).Value =
CDate(dtEnd)
.Parameters.Add("@Count", SqlDbType.Int).Value = txtCount.Text
.Parameters.Add("@Description", SqlDbType.VarChar, 500).Value =
txtDesc.Text
End With
sqlDapter.InsertCommand = sqlCmd
sqlConn.Open()
sqlCmd.ExecuteNonQuery()
sqlDapter.Update(dSet.Tables("ETS"))
rptrETS.DataSource = dSet.Tables("ETS").DefaultView
rptrETS.DataBind()
-----------------------
As already said, the just inserted record is not getting reflected in
the Repeater though I am updating the DataSet.
Can someone please point out where am I erring & how can I make the
Repeater display the newly inserted record?
Thanks
clicked, I want 2 things:
- the record is inserted in a database
- the Repeater should display the just inserted record (along with the
other records).
I could implement the first but not the second. This is how I tried it
(this is the OnClick event function of the Button):
-----------------------
Dim dSet As DataSet
Dim sqlCmd As SqlCommand
Dim sqlConn As SqlConnection
Dim sqlDapter As SqlDataAdapter
sqlConn = New SqlConnection("......")
sqlDapter = New SqlDataAdapter
sqlCmd = New SqlCommand("SELECT * FROM ETS ORDER BY EID", sqlConn)
sqlDapter.SelectCommand = sqlCmd
dSet = New DataSet
sqlDapter.Fill(dSet, "ETS")
sqlCmd = New SqlCommand("INSERT INTO ETS (SDateTime, EDateTime, Count,
Description) VALUES (@SDateTime, @EDateTime, @Count, @Description)",
sqlConn)
With sqlCmd
.Parameters.Add("@SDateTime", SqlDbType.DateTime).Value =
CDate(dtStart)
.Parameters.Add("@EDatetIme", SqlDbType.DateTime).Value =
CDate(dtEnd)
.Parameters.Add("@Count", SqlDbType.Int).Value = txtCount.Text
.Parameters.Add("@Description", SqlDbType.VarChar, 500).Value =
txtDesc.Text
End With
sqlDapter.InsertCommand = sqlCmd
sqlConn.Open()
sqlCmd.ExecuteNonQuery()
sqlDapter.Update(dSet.Tables("ETS"))
rptrETS.DataSource = dSet.Tables("ETS").DefaultView
rptrETS.DataBind()
-----------------------
As already said, the just inserted record is not getting reflected in
the Repeater though I am updating the DataSet.
Can someone please point out where am I erring & how can I make the
Repeater display the newly inserted record?
Thanks