I haven't written any .net database updates before. I wrote the following code for a visual web developer application and it appears to work. There is no close function or anything. Will the adapter, builder, dataset, and row objects be cleaned up and disposed of properly? Please tell me if I need to include anything else. The connection object is made elsewhere. Thanks
Dim adapterAsNew Data.SqlClient.SqlDataAdapter("SELECT * FROM Inventory WHERE InUnique=" & ListValue.Value, connect)Dim builderAsNew Data.SqlClient.SqlCommandBuilder(adapter)
Dim datasetAs Data.DataSet =New Data.DataSet()adapter.Fill(dataset,"Inventory")
Dim datarowAs Data.DataRow = dataset.Tables(0).Rows(0)datarow("InAgUnique") = Val(InAgUnique.Text)
datarow("InTyUnique") = Val(InTyUnique.Text)datarow("InName") = InName.Text
datarow("InPnUniquePrimary") = Val(InPnUniquePrimary.Text)datarow("InPnUniqueSecondary") = Val(InPnUniqueSecondary.Text)
datarow("InPnUniqueTertiary") = Val(InPnUniqueTertiary.Text)datarow("InPnUniqueSupervisor") = Val(InPnUniqueSupervisor.Text)
datarow("InDescription") = InDescription.Textdatarow("InProblemInstructions") = InProblemInstructions.Text
adapter.Update(dataset,"Inventory")
If the connection is not open, Adapter would open it and once done with the operation, would close itself (as per .net 1.1), not sure of the chanegs in 2.0 though!
No comments:
Post a Comment