findcausene
07-02-2008, 09:40 AM
I need help in using code to modify the data in a dataset.
The code I am using is:
------------------------------------------------------------------------------------------------------------------------------------------ '-- Open a database connection</o:p>
Dim DBConnection As New OleDbConnection( _</o:p>
"Provider=Microsoft.Jet.OLEDB.4.0;" & _</o:p>
"Data Source=" & Server.MapPath("~/app_data/capsDb1.mdb"))</o:p>
DBConnection.Open()</o:p>
</o:p>
'-- Issue an SQL command through the database connection</o:p>
Dim SQLString As String</o:p>
' SQLString = "SELECT CID, SID, [Investigation Title], [Date Accessed] FROM [Status Table] ORDER BY SID"</o:p>
SQLString = "SELECT [Questions Table].QTPriority, [AI Questions Table].AIID, [AI Questions Table].Question, [AI Questions Table].Rationale FROM ((([AI Questions Table] INNER JOIN [Questions Table] ON [AI Questions Table].AIID = [Questions Table].AIID) INNER JOIN [Status Table] ON [Questions Table].SID = [Status Table].SID) INNER JOIN [Characteristics Table] ON [Status Table].CID = [Characteristics Table].CID) WHERE ([Characteristics Table].Defect = 'Dissolution') ORDER BY [AI Questions Table].AIID Desc"</o:p>
Dim DBCommand As New OleDbCommand(SQLString, DBConnection)</o:p>
</o:p>
'set up DataSet and DataAdapter</o:p>
Dim myDataSet As New DataSet</o:p>
</o:p>
Dim myDataAdapter As OleDbDataAdapter</o:p>
myDataAdapter = New OleDbDataAdapter(DBCommand)</o:p>
myDataAdapter.Fill(myDataSet)</o:p>
</o:p>
Response.Write(myDataAdapter("Question"))</o:p>
</o:p>
'bind the dataSet to the GridView</o:p>
GridView1.DataSource = myDataSet</o:p>
GridView1.DataBind()</o:p>
</o:p>
DBConnection.Close()</o:p>
-----------------------------------------------------------------------------
The error message I get is
------------------------------------------------------------------------------------------------------------------------------------
Server Error in '/WebSite10' Application. </o:p>
Compilation Error </o:p>
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: BC30367: Class 'System.Data.OleDb.OleDbDataAdapter' cannot be indexed because it has no default property.
Source Error:</o:p>
</o:p>
Line 30: myDataAdapter.Fill(myDataSet)</o:p>
Line 31: </o:p>
Line 32: Response.Write(myDataAdapter("Question"))</o:p>
Line 33: </o:p>
Line 34: 'bind the dataSet to the GridView</o:p>
</o:p>
If I change Line 32 to read myDataSet.?Question?) = ?XXX? I get the same error. What can I do that will lwt me modify data in the various columns? Any help will be appreciated as this has stumped me for some time.
Thanks in advance.
Charlie
The code I am using is:
------------------------------------------------------------------------------------------------------------------------------------------ '-- Open a database connection</o:p>
Dim DBConnection As New OleDbConnection( _</o:p>
"Provider=Microsoft.Jet.OLEDB.4.0;" & _</o:p>
"Data Source=" & Server.MapPath("~/app_data/capsDb1.mdb"))</o:p>
DBConnection.Open()</o:p>
</o:p>
'-- Issue an SQL command through the database connection</o:p>
Dim SQLString As String</o:p>
' SQLString = "SELECT CID, SID, [Investigation Title], [Date Accessed] FROM [Status Table] ORDER BY SID"</o:p>
SQLString = "SELECT [Questions Table].QTPriority, [AI Questions Table].AIID, [AI Questions Table].Question, [AI Questions Table].Rationale FROM ((([AI Questions Table] INNER JOIN [Questions Table] ON [AI Questions Table].AIID = [Questions Table].AIID) INNER JOIN [Status Table] ON [Questions Table].SID = [Status Table].SID) INNER JOIN [Characteristics Table] ON [Status Table].CID = [Characteristics Table].CID) WHERE ([Characteristics Table].Defect = 'Dissolution') ORDER BY [AI Questions Table].AIID Desc"</o:p>
Dim DBCommand As New OleDbCommand(SQLString, DBConnection)</o:p>
</o:p>
'set up DataSet and DataAdapter</o:p>
Dim myDataSet As New DataSet</o:p>
</o:p>
Dim myDataAdapter As OleDbDataAdapter</o:p>
myDataAdapter = New OleDbDataAdapter(DBCommand)</o:p>
myDataAdapter.Fill(myDataSet)</o:p>
</o:p>
Response.Write(myDataAdapter("Question"))</o:p>
</o:p>
'bind the dataSet to the GridView</o:p>
GridView1.DataSource = myDataSet</o:p>
GridView1.DataBind()</o:p>
</o:p>
DBConnection.Close()</o:p>
-----------------------------------------------------------------------------
The error message I get is
------------------------------------------------------------------------------------------------------------------------------------
Server Error in '/WebSite10' Application. </o:p>
Compilation Error </o:p>
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: BC30367: Class 'System.Data.OleDb.OleDbDataAdapter' cannot be indexed because it has no default property.
Source Error:</o:p>
</o:p>
Line 30: myDataAdapter.Fill(myDataSet)</o:p>
Line 31: </o:p>
Line 32: Response.Write(myDataAdapter("Question"))</o:p>
Line 33: </o:p>
Line 34: 'bind the dataSet to the GridView</o:p>
</o:p>
If I change Line 32 to read myDataSet.?Question?) = ?XXX? I get the same error. What can I do that will lwt me modify data in the various columns? Any help will be appreciated as this has stumped me for some time.
Thanks in advance.
Charlie