InterviewSolution
Saved Bookmarks
| 1. |
Solve : storing the array values into a database table? |
|
Answer» HI, I’m trying to WRITE a program that stores the values in an array into a database table. The name of the database is Company.mdb and the table that I want to store values is called Employee. Below is the procedure that is supposed to perform the task. The problem is it doesn’t store the array(strEmployeeRecord) values into the table. NOTHING happens. Can someone please help me with this problem? I’m using Visual Studio 2005. Thanks in advance. Code: [Select]Private Sub StoreInTable() Dim strSQL As String = "INSERT INTO Employee FROM ARRAY strEmployeeRecord " 'strPath PROVIDES the database type and path of the Route database Dim strPath As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _ "Data Source = D:\Company.mdb" Dim odaRoute As New OleDb.OleDbDataAdapter(strSQL, strPath) odaRoute.Dispose() End Sub I know working with VB.net AND Ms Access can be a *censored* hole, it makes me angry!! 1. I think you haven't got enough connection link... 2. You can't just stick an array into a database field like that you need to write some more code If i think i know what you is trying to do then this might help: Code: [Select]Try Dim objRow As DataRow Dim tableName As String = "highScore" Dim objDataSet As New DataSet dbConnection = New OleDb.OleDbConnection(ConnectionString) dbAdapter = New OleDb.OleDbDataAdapter("SELECT * FROM " & tableName & "", ConnectionString) Dim NewCommand = New OleDb.OleDbCommandBuilder(dbAdapter) dbAdapter.FillSchema(objDataSet, SchemaType.Source, tableName) dbAdapter.Fill(objDataSet, tableName) objRow = objDataSet.Tables(tableName).Rows.Add Dim rowNum = objDataSet.Tables(tableName).Rows.Count objRow = objDataSet.Tables(tableName).Rows.Find(rowNum) ''This is how you would write code that will store all data in array into each database row For i = 0 to Array.Length - 1 objRow.Item(i) = Array(i) Next dbAdapter.Update(objDataSet, tableName) Catch ex As Exception MsgBox(ex.Message) End TryThanx 4 the reply TChai I'd already given up on getting help on this post Yes, it'z what i've been trying to do. I'll try your code out and see if it works... |
|