dcwm
09-26-2009, 10:22 AM
I have been trying to split up working code so as to have it in two bits [ GetTheInfo and PutTheInfo ] in app_code, and so that I can call up the data from any aspx.vb page with the minimum code writing on the aspx.vb page.
I've managed to get the datatable out of the database, but I can't figure out how to get it back there. I seem to have a bit of a blind spot about how it all works. I should be grateful for some advice.
In App_code, I have two methods, one of which works and another one which is obviously rot.
<code>
Imports Microsoft.VisualBasic
Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports System.Configuration
Imports System.IO
Imports System.Web.UI.HtmlControls
Imports System.Web.UI.WebControls
Public Class GetAndPut
Public Function GetTheInfo() As DataTable
'
' GET MATERIAL FROM SQL ON REMOTE SERVER
'
Dim conS As String
conS = ConfigurationManager.ConnectionStrings("TieKnot").ConnectionString
'
Dim RemoteTableName As String
RemoteTableName = "BulkPurchase"
'
Dim qS As String = "SELECT * FROM " & RemoteTableName
'
Dim sqlCon As SqlConnection = New SqlConnection(conS)
sqlCon.Open()
'
Dim daX As SqlDataAdapter = New SqlDataAdapter(qS, sqlCon)
Dim dsKor As DataSet = New DataSet
daX.FillSchema(dsKor, SchemaType.Source, RemoteTableName)
daX.Fill(dsKor, RemoteTableName)
'
Dim LT As DataTable
LT = dsKor.Tables(RemoteTableName)
'
sqlCon.Close()
'
Return LT
'
End Function
Public Sub PutTheInfo(ByVal LT As DataTable)
'
' SEND MATERIAL BACK TO SQL ON REMOTE SERVER
'
Dim conS As String
conS = ConfigurationManager.ConnectionStrings("TieKnot").ConnectionString
Dim RemoteTableName As String
RemoteTableName = "BulkPurchase"
Dim qS As String = "SELECT * FROM " & RemoteTableName
Dim sqlCon As SqlConnection = New SqlConnection(conS)
Dim daX As SqlDataAdapter = New SqlDataAdapter(qS, sqlCon)
Dim dsKor As DataSet = New DataSet
'
Dim objcommandbuilder As New SqlCommandBuilder(daX)
daX.Update(dsKor, RemoteTableName)
'
sqlCon.Close()
'
End Sub
</code>
On a Page20.aspx.vb I called up the information as follows and this works OK
<code>
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
'
' Get the existing table
'
Dim LocalTable As DataTable
Dim z As New GetAndPut()
LocalTable = z.GetTheInfo()
'
Dim MyRow As DataRow ' *******
Dim MyCol As DataColumn
Dim aja As String, ajb As String
'
MyRow = LocalTable.Rows.Item(2)
MyCol = LocalTable.Columns.Item(2)
aja = MyRow(MyCol)
Label2.Text = aja ' OK TO HERE
'
ajb = "roffle"
MyRow(MyCol) = ajb
'
z.PutTheInfo(LocalTable) ' LAST THREE LINES AND/OR PutTheInfo are NBG
'
End Sub
</code>
I've managed to get the datatable out of the database, but I can't figure out how to get it back there. I seem to have a bit of a blind spot about how it all works. I should be grateful for some advice.
In App_code, I have two methods, one of which works and another one which is obviously rot.
<code>
Imports Microsoft.VisualBasic
Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports System.Configuration
Imports System.IO
Imports System.Web.UI.HtmlControls
Imports System.Web.UI.WebControls
Public Class GetAndPut
Public Function GetTheInfo() As DataTable
'
' GET MATERIAL FROM SQL ON REMOTE SERVER
'
Dim conS As String
conS = ConfigurationManager.ConnectionStrings("TieKnot").ConnectionString
'
Dim RemoteTableName As String
RemoteTableName = "BulkPurchase"
'
Dim qS As String = "SELECT * FROM " & RemoteTableName
'
Dim sqlCon As SqlConnection = New SqlConnection(conS)
sqlCon.Open()
'
Dim daX As SqlDataAdapter = New SqlDataAdapter(qS, sqlCon)
Dim dsKor As DataSet = New DataSet
daX.FillSchema(dsKor, SchemaType.Source, RemoteTableName)
daX.Fill(dsKor, RemoteTableName)
'
Dim LT As DataTable
LT = dsKor.Tables(RemoteTableName)
'
sqlCon.Close()
'
Return LT
'
End Function
Public Sub PutTheInfo(ByVal LT As DataTable)
'
' SEND MATERIAL BACK TO SQL ON REMOTE SERVER
'
Dim conS As String
conS = ConfigurationManager.ConnectionStrings("TieKnot").ConnectionString
Dim RemoteTableName As String
RemoteTableName = "BulkPurchase"
Dim qS As String = "SELECT * FROM " & RemoteTableName
Dim sqlCon As SqlConnection = New SqlConnection(conS)
Dim daX As SqlDataAdapter = New SqlDataAdapter(qS, sqlCon)
Dim dsKor As DataSet = New DataSet
'
Dim objcommandbuilder As New SqlCommandBuilder(daX)
daX.Update(dsKor, RemoteTableName)
'
sqlCon.Close()
'
End Sub
</code>
On a Page20.aspx.vb I called up the information as follows and this works OK
<code>
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
'
' Get the existing table
'
Dim LocalTable As DataTable
Dim z As New GetAndPut()
LocalTable = z.GetTheInfo()
'
Dim MyRow As DataRow ' *******
Dim MyCol As DataColumn
Dim aja As String, ajb As String
'
MyRow = LocalTable.Rows.Item(2)
MyCol = LocalTable.Columns.Item(2)
aja = MyRow(MyCol)
Label2.Text = aja ' OK TO HERE
'
ajb = "roffle"
MyRow(MyCol) = ajb
'
z.PutTheInfo(LocalTable) ' LAST THREE LINES AND/OR PutTheInfo are NBG
'
End Sub
</code>