|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Newbie Add Row QuestionI'm fairly new to vb/ado.net and am having a hard time adding a row to a table. The following code executes without any exceptions, but the rows do not appear in the database. Also, I've stepped through the entire thing and the RowState property never changes from "detached". Any help would be greatly appreciated! -------------------------------------------------------------------------------------------------------------------- Dim retList as array Dim strArray as Object Dim i as Integer Dim cnConn As New SqlConnection Dim da As SqlDataAdapter Dim ds As DataSet Dim dt As DataTable Dim dr As DataRow Dim drc As DataRowCollection cnConn.ConnectionString = _ "Data Source=" & strServer & ";" & _ "Initial Catalog=" & strDatabase & ";" & _ "Integrated Security=SSPI" cnConn.Open() da = New SqlDataAdapter("select * from tProviders", cnConn) ds = New DataSet("tProviders") da.Fill(ds, "tProviders") dt = New DataTable dt = ds.Tables("tProviders") drc = dt.Rows For i = (LBound(retList) + 1) To UBound(retList) strArray = Split(retList(i), "^") dr = dt.NewRow drc.Add(strArray) Next -------------------------------------------------------------------------------------------------------------------- Datasets and datatables are detached. Adding to those do not do anything.
You need to write this data back to the database. There are several methods to this. The Data adapter can do this for you. Look into CurrencyManager (yes.. weird name).. Show quoteHide quote "phenderson" <paul.m.hender***@gmail.com> wrote in message news:1160680266.020821.287350@i42g2000cwa.googlegroups.com... > Hi, > > I'm fairly new to vb/ado.net and am having a hard time adding a row to > a table. The following code executes without any exceptions, but the > rows do not appear in the database. Also, I've stepped through the > entire thing and the RowState property never changes from "detached". > Any help would be greatly appreciated! > > -------------------------------------------------------------------------------------------------------------------- > Dim retList as array > Dim strArray as Object > Dim i as Integer > Dim cnConn As New SqlConnection > Dim da As SqlDataAdapter > Dim ds As DataSet > Dim dt As DataTable > Dim dr As DataRow > Dim drc As DataRowCollection > > cnConn.ConnectionString = _ > "Data Source=" & strServer & ";" & _ > "Initial Catalog=" & strDatabase & ";" & _ > "Integrated Security=SSPI" > > cnConn.Open() > > da = New SqlDataAdapter("select * from tProviders", cnConn) > ds = New DataSet("tProviders") > da.Fill(ds, "tProviders") > > dt = New DataTable > dt = ds.Tables("tProviders") > drc = dt.Rows > > For i = (LBound(retList) + 1) To UBound(retList) > > strArray = Split(retList(i), "^") > > dr = dt.NewRow > > drc.Add(strArray) > > Next > -------------------------------------------------------------------------------------------------------------------- >
some general mouse events should be there
newbie question Memory leaks? "Optional" reference? Convert C# "writer.Write(@" to VB ? VB.net 2003/2005- Can't figure out how to test for working internet connection ASP web app VS 2005 nightmares Adding a control programmatically... Oracle throwing an exception, "ORA-01036: illegal variable name/nu |
|||||||||||||||||||||||