Public TheConnection As SqlConnection = New SqlConnection("Data Source=YOURSERVER;User Id=YOURUSERS;Password=YOURPASSWORD;Initial Catalog=northwind")
Public Function GetCustomers() As DataSet
Dim custDa As SqlDataAdapter = New SqlDataAdapter("Select CustomerId, CompanyName From Customers", TheConnection)
Dim custDs As DataSet = New DataSet()
custDa.MissingSchemaAction = MissingSchemaAction.AddWithKey
custDa.Fill(custDs, "Customers")
GetCustomers = custDs
End Function
Public Function UpdateCustomers(ByVal custDs As DataSet) As DataSet
Dim custDa As SqlDataAdapter = New SqlDataAdapter
custDa.InsertCommand = New SqlCommand("INSERT INTO CUSTOMERS(CustomerId, CompanyName) Values (@CustomerId, @CompanyName)", TheConnection)
custDa.InsertCommand.Parameters.Add("@CustomerId", SqlDbType.NChar, 5, "CustomerId")
custDa.InsertCommand.Parameters.Add("@CompanyName", SqlDbType.NChar, 15, "CompanyName")
custDa.UpdateCommand = New SqlCommand("UPDATE CUSTOMERS SET CUSTOMERID=@CUSTOMERID, COMPANYNAME=@COMPANYNAME WHERE CUSTOMERID=@OLDCUSTOMERID", TheConnection)
custDa.UpdateCommand.Parameters.Add("@CustomerId", SqlDbType.NChar, 5, "CustomerId")
custDa.UpdateCommand.Parameters.Add("@CompanyName", SqlDbType.NChar, 15, "CompanyName")
Dim oPrmUpdate As SqlParameter = custDa.UpdateCommand.Parameters.Add("@OLDCUSTOMERID", SqlDbType.NChar, 15, "CustomerId")
oPrmUpdate.SourceVersion = DataRowVersion.Original
custDa.DeleteCommand = New SqlCommand("DELETE FROM CUSTOMERS WHERE CUSTOMERID=@CUSTOMERID", TheConnection)
Dim oPrmDelete As SqlParameter = custDa.DeleteCommand.Parameters.Add("@CustomerId", SqlDbType.NChar, 5, "CustomerId")
oPrmDelete.SourceVersion = DataRowVersion.Original
custDa.Update(custDs, "Customers")
UpdateCustomers = custDs
End Function