|
Can anyone see why this insert command is not working? It is not generating any error messages. It acts as if it has inserted the records, but when I check the database the row count is still 0.
Here is my code... <hr> <color="Blue"> Public Sub UploadJournals() 'Import table structure. Dim mSQL As String = "SELECT * FROM salejnls" Dim conStr As String = "Persist Security Info=False;database=DDMS;server=localhost;user id=xxx;Password=xxx" Dim salesDS As New DataSet() Dim MyConn As New MySqlConnection(conStr) Dim MyDA As New MySqlDataAdapter(mSQL, MyConn) MyDA.Fill(salesDS , "salejnls") MyConn.Close()
Console.WriteLine("Database structure loaded.")
'Create complete list of all sales information Dim vfCStr As String = "Provider=VFPOLEDB.1;Data Source=C:\Jnls;Cache Authentication=False;Mask Password=False;persist secur" & _ "ity info=False;Mode=Share Deny None;Extended Properties=;Encrypt Password=False" Dim vfConn As New OleDbConnection(vfCStr) Dim vfDA As New OleDbDataAdapter(vfSQL, vfConn)
Console.WriteLine("Gathering data...") Dim sTime As Date sTime = System.Date.Now Try vfDA.Fill(salesDS, "salejnls") Catch ex As Exception Console.Write(ex) End Try Console.WriteLine(salesDS.Tables("salejnls").Rows.Count & " records in journals.") Console.WriteLine("Now Uploading data...") 'Create update command Try MyDA.TableMappings.Add("salejnls", "salejnls") Dim iCmd As MySqlCommand iCmd = New MySqlCommand("INSERT INTO salejnls(KEYS,ORDER,P_C_NBR, P_C_DEPT,P_NUMBER, P_DASH" VALUES (@KEYS,@ORDER,@P_C_NBR,@P_C_DEPT,@P_NUMBER,@P_DASH)")
iCmd.Parameters.Add(New MySqlParameter("@KEYS", OleDbType.VarWChar, 40)) iCmd.Parameters.Add(New MySqlParameter("@ORDER", OleDbType.VarWChar, 20)) iCmd.Parameters.Add(New MySqlParameter("@P_C_NBR", OleDbType.VarWChar, 10)) iCmd.Parameters.Add(New MySqlParameter("@P_C_DEPT", OleDbType.VarWChar, 4)) iCmd.Parameters.Add(New MySqlParameter("@P_NUMBER", OleDbType.VarWChar, 8)) iCmd.Parameters.Add(New MySqlParameter
MyDA = New MySqlDataAdapter(mSQL, MyConn) MyDA.InsertCommand = iCmd
MyDA.Update(salesDS, "salejnls") Catch ex As Exception Console.Write(ex) End Try
Dim eTime As Date eTime = System.Date.Now
Dim dTime As Integer dTime = DateAndTime.DateDiff(DateInterval.Minute, sTime, eTime)
Console.WriteLine("There were " & salesDS.Tables("salejnls").Rows.Count() - 1 & " records created. In " & dTime & " minutes.") End Sub End Class</color> | | MigrationUser 1 Monday, February 07, 2005 5:01 PM | MyDA = New MySqlDataAdapter(mSQL, MyConn) MyDA.InsertCommand = iCmd MyDA.Update(salesDS, "salejnls")
I believe this is unnecessary. The .Update() command is based of what you already have. I'd suggest just calling the .ExecuteNonQuery() of the command object rather than fiddling with the DataAdapter. | | MigrationUser 1 Monday, February 07, 2005 8:39 PM | That is how I have always done it with Access. If I use ExecuteNonQuery how does it know to use the Dataset to update the Database?
Could you provide an example?? | | MigrationUser 1 Tuesday, February 08, 2005 9:37 AM | Last time I've used the .Update method from an adapter, it was using a select statement as the base. Also, the .Update relies on the rowstate to determine what to do when it's executing.
personally, I'd iterate using bulkinsert rather than fiddling with the dataadapter. That could potentially take a LONG time! That would explain the 30 minutes.
I see nothing happening because you haven't changed anything in the DataSet meaning nothing was flagged to be updated or inserted.
http://www.sswug.com/see/19511 | | MigrationUser 1 Tuesday, February 08, 2005 12:08 PM | The dataset has changed though. vfDA.Fills the dataset with as you put it, "the gnarly select statement". This is a custom class and the SELECT statement is being passed to it through a public variable "vfSQL".
I know that the dataset is being filled, because its row count is being reported correctly.
Once that dataset is filled with all my journals I need it to insert it into the MySQL Table salejnls. | | MigrationUser 1 Tuesday, February 08, 2005 1:08 PM | It looks like you're wiping out your DataSet before you use the values from SQL...
First you fill your dataset:
MyDA.Fill(salesDS , "salejnls")
This is filling salesDS with the records in the local SQL database. But then, before you do anything with that data, you're reloading the DataSet with new data:
vfDA.Fill(salesDS, "salejnls")
So you've basically emptied the table "salejnls" of all SQL DataAdapter records and replaced them with the OLEDB records.
Then you create an update query for the OLEDB DataAdapter but you don't add any itmes to the DataSet.
It looks like you want two instances of your DataSet, one filled from SQL the other filled from OLEDB. Then you want to add all the records from DataSet1 to DataSet2. Then call the OLEDB update on dataset2.
I'd also recommed creating your DataAdapters and DataSet at design time. The entire .NET data environment is much easier to use this way. You only need to provide the SELECT command statement and the DE generates the rest of the commands (use the DataAdapter Wizard).
| | MigrationUser 1 Tuesday, February 08, 2005 1:17 PM | Originally I had two datasets and was just setting one equal too two.
This is what I need to accomplish.
1. Pull all records from several visual FoxPro free tables. 2. Store that information into a Dataset. 3. Insert the Records in the Dataset into the MySQL Table.
Something like this. <hr>
<color="Blue"> Public Sub UploadJournals()
Dim salesDS As New DataSet()</color> <color="Green">'Create connection to Foxpro Database</color><color="Blue"> Dim vfCStr As String = "Provider=VFPOLEDB.1;Data Source=C:\Jnls;Cache Authentication=False;Mask Password=False;persist secur" & _ "ity info=False;Mode=Share Deny None;Extended Properties=;Encrypt Password=False" Dim vfSQL As String = "SELECT * FROM jnl1 UNION SELECT * FROM jnl2" Dim vfConn As New OleDbConnection(vfCStr) Dim vfDA As New OleDbDataAdapter(vfSQL, vfConn)
</color><color="Green">'Set Start Time</color><color="Blue"> Dim sTime As Date = System.Date.Now Try vfDA.Fill(salesDS, "salejnls") </color><color="Green">'Filled from Foxpro Database</color><color="Blue"> Catch ex As Exception Console.Write(ex) End Try </color><color="Green">'Create connection to MySQL Database</color><color="Blue"> Dim conStr As String = "Persist Security Info=False;database=Test;server=localhost;user id=xxx;Password=xxx" Dim MyConn As New MySqlConnection(conStr) Dim MyDA As New MySqlDataAdapter(mSQL, MyConn) </color><color="Green">'Create update command</color><color="Blue"> Try MyDA.TableMappings.Add("salejnls", "salejnls") Dim iCmd As MySqlCommand iCmd = New MySqlCommand("INSERT INTO salejnls(KEYS,ORDER,P_C_NBR, P_C_DEPT,P_NUMBER, P_DASH)" VALUES (@KEYS,@ORDER,@P_C_NBR,@P_C_DEPT,@P_NUMBER,@P_DASH)") iCmd.Parameters.Add(New MySqlParameter("@KEYS", MySQLDbType.VarChar, 40)) iCmd.Parameters.Add(New MySqlParameter("@ORDER", MySQLDbType.VarChar, 20)) iCmd.Parameters.Add(New MySqlParameter("@P_C_NBR", MySQLDbType.VarChar, 10)) iCmd.Parameters.Add(New MySqlParameter("@P_C_DEPT", MySQLDbType.VarChar, 4)) iCmd.Parameters.Add(New MySqlParameter("@P_NUMBER", MySQLDbType.VarChar, 8)) iCmd.Parameters.Add(New MySqlParameter
MyDA = New MySqlDataAdapter(mSQL, MyConn) MyDA.InsertCommand = iCmd MyDA.Update(salesDS, "salejnls")</color><color="Green">'Update using Dataset filled with Foxpro records.</color><color="Blue"> Catch ex As Exception Console.Write(ex) End Try
</color><color="Green">'Set End Time</color><color="Blue"> Dim eTime As Date = System.Date.Now Dim dTime As Integer = DateAndTime.DateDiff(DateInterval.Minute, sTime, eTime)
</color><color="Green">'Display Results</color><color="Blue"> Console.WriteLine("There were " & salesDS.Tables("salejnls").Rows.Count() - 1 & " records created. In " & dTime & " minutes.")
End Sub </color>
| | MigrationUser 1 Tuesday, February 08, 2005 2:15 PM | The problem is that you still aren't making any "changes" to the data of your DataSet before you call Update.
The MyDA.Update method is going through each row of the Table "salejnls" in the DataSet salesDS and looking at the RowState to determine if the row has been modified. If it has, the Update method then calls the approprite Command for the type of change:
Row Added = Call Insert Command Row Deleted = Call Delete Command Row Modified = Call Update Command
When you fill salesDS from the FoxPro data source, the records are all loaded into the DataSet and each has a RowState of "unchanged". You then call the update method of the SQL DataAdapter against the same DataSet. The update method does not find any rows with a RowState of something other than "unchanged", so it does nothing.
This is why you need two DataSets. By Filling DS1 from FoxPro and then adding those records to an empty DS2 (both of which are instances of your salesDS DataSet), the update command will see all of the records in DS2 as "added" rather than "unchanged" and will execute the Insert Command for each.
Hope this clears it up! | | MigrationUser 1 Tuesday, February 08, 2005 5:31 PM | Yes, that does help a lot, but I still need some assistance on exactly how to bring the datarows into the second dataset. I tried. 1. Fill DS1 From FoxPro. 2. Use a For Each loop to import rows from DS1 to DS2 Example <hr> For Each dr In DS1.Tables(0).Rows DS2.Tables(0).ImportRow(dr) Next 'Still produces a rowstate of 2 or unchanged.
1. Fill DS1 from FoxPro. 2. Use a For Each loop to add rows from DS1 to DS2 Example <hr> For Each dr In DS1.Tables(0).Rows DS2.Tables(0).Rows.Add(dr) Next 'Gives me an error: This row already belongs to another table. | | MigrationUser 1 Wednesday, February 09, 2005 11:11 AM | The following will get it for you:
Dim enm As IEnumerator = DS1.Tables(0).Rows.GetEnumerator
While enm.MoveNext
Dim r As DataRow = DS2.Tables(0).NewRow r.ItemArray = CType(enm.Current, DataRow).ItemArray DS2.Tables(0).Rows.Add(r)
End While
Just be sure that AcceptChanges is NOT called on DS2 before you use it in your Update method.
( Note that you could use the For-Next Loop:
For i as Integer = 0 To DS1.Tables(0).Rows.Count - 1
Dim r As DataRow = DS2.Tables(0).NewRow r.ItemArray = DS1.Tables(0).Rows.Item(i).ItemArray DS2.Tables(0).Rows.Add(r)
Next
I just prefer GetEnumerator as it is faster and cannot go out of bounds.) | | MigrationUser 1 Wednesday, February 09, 2005 12:36 PM | Thanks for the help rkimble.
I changed my code to use the IEnumerator, and the row state is changing to 4, but now I'm getting the System.OutOfMemoryException. It also takes forever. It took 159 minutes to build the dataset and try to Insert all the rows. I know that the original For Each Loop that was using Rows.Add(dr) wasn't changing the RowState, but it would only take about 35 minutes to run. Is there anyway of doing this better so as to avoide the OutOfMemoryException, and make it loop through faster. It is returning just over 320,000 records.
I would like to keep this under 40 minutes.
Information about the Machine... <hr> PC Clone Windows 2003 Server Web Edition AMD Athlon XP 2000+ (1.67GHz) 768 RAM | | MigrationUser 1 Wednesday, February 09, 2005 4:52 PM | Thank you for the help rkimble.
I changed my code to use the IEnumerator, but now I'm getting a System.OutofMemoryException Error. This is a fairly large table with just over 320,000 records and growing. Is there maybe a better way of doing this? Also when I was using the For Each Loop to add the DataRow it was only taking about 35 minutes. I know that it wasn't changing the RowState, but why such an increase in time? It took 155 minutes to run it with IEnumerator.
One last thing can you explain to me what you ment by <color="Green"><i><b>Just be sure that AcceptChanges is NOT called on DS2 before you use it in your Update method.</b></i></color>
Thanks again!
Specs for my Computer... <hr> PC CLone Windows 2003 Server Web Addition AMD Athlon XP 2000+ (1.67GHz) 768MB of Ram | | MigrationUser 1 Thursday, February 10, 2005 9:19 AM | Sorry for posting the same thing twice. The first post was done yesterday and didn't show up until this morning.
Anyways I figured out why I was getting the OutOfMemoryException. I had forgotten to take the IEnumerator out of the For Each Row in DS1.Tables(0).Rows Loop. So it was performing the While Loop inside of the For Loop.
Could you tell me though if there is perhaps a more efficient means of doing this, and is 40 to 60 minutes a reasonable amount of time to process 320,000 records?
| | MigrationUser 1 Thursday, February 10, 2005 12:33 PM | What I meant by "Just be sure that AcceptChanges is NOT called on DS2 before you use it in your Update method." is that if you should explicitly call (or use a control that calls) AcceptChanges on DS2, all of the rows you added will have their RowState reset to Unchanged. Then there will be nothing for the Update method to process.
As far as the amount of time goes... That does seem a bit excessive. I really wouldn't think that the loop for copying the records would take that long...
Do you know which parts of your process take the longest? You might implement some TimeSpan variables and write to the consol the amount of time that elapses between:
1. Starting execution of data processing and Getting Filled DataSet from FoxPro 2. Start and End of While loop 3. End of while loop and udpate of SQL
Also, does the server have plenty of available resources, or is it overworked? Is this a Windows Forms project or a Web Forms project? If it is a web project, is IIS giving the process enough processor time and resources to do the work as fast as possible?
I'd like another opinion from one of the data experts, but I still think that sounds like it is taking longer than it should. | | MigrationUser 1 Thursday, February 10, 2005 1:02 PM | The App. is simply a windows console application that will function as a proc. I plan on scheduling it through windows scheduler and executing it every night when the system is being used the least.
As far as available resources, the system only host two very simple websites that function more as billboards than anything else. MySQL is installed and running as well as Symantec AV Corporate Addition. Other than that it should just be standard windows processes.
To the question, which part takes the longest. That would be the insert command. I'm writing back to the console whenever it starts each step, and it has taken more than 1½ hours so far. I checked the MySQL table with MySQL Administrator and there have only been 28,204 records added at this point. At this pace it will take more than 17 hours.
Here is exactly what I have so far. <hr> <color="Blue"> Public Sub UploadJournals()
'Create complete list of all sales information Dim vfDS As New DataSet() Dim vfCStr As String = "Provider=VFPOLEDB.1;Data Source=C:\Jnls;Cache Authentication=False;Mask Password=False;persist secur" & _ "ity info=False;Mode=Share Deny None;Extended Properties=;Encrypt Password=False" Dim vfConn As New OleDbConnection(vfCStr) Dim vfDA As New OleDbDataAdapter(vfSQL, vfConn)
Console.WriteLine("Gathering data...")
Dim sTime As Date 'Start Time sTime = System.Date.Now Try vfDA.Fill(vfDS, "ddjnls") 'Fill FoxPro DataSet vfConn.Close() Catch ex As Exception Console.Write(ex) End Try Console.WriteLine(vfDS.Tables("ddjnls").Rows.Count & " records in journals.")
'Import MySQL table structure. Dim mSQL As String = "SELECT * FROM salejnls" Dim salesDS As New DataSet() Dim conStr As String = "Persist Security Info=False;database=Journals;server=localhost;user id=XX;Password=XXX" Dim MyConn As New MySqlConnection(conStr) Dim MyDA As New MySqlDataAdapter(mSQL, MyConn) MyDA.Fill(salesDS , "salejnls") MyConn.Close() Console.WriteLine("Database structure loaded.")
Console.WriteLine("Now Transfering Records...") 'Create update command
'Loop though and import rows into SQL Dataset Dim dr As DataRow Try Dim enm As IEnumerator = vfDS.Tables("ddjnls").Rows.GetEnumerator While enm.MoveNext dr = salesDS.Tables("salejnls").NewRow() dr.ItemArray = CType(enm.Current, DataRow).ItemArray salesDS.Tables("salejnls").Rows.Add(dr) End While Catch ex As Exception Console.WriteLine(ex) End Try
Console.WriteLine("Now Updating MySQL...")
Try MyDA.TableMappings.Add("salejnls", "salejnls") Dim iCmd As MySqlCommand iCmd = New MySqlCommand("INSERT INTO salejnls(`KEYS`, `ORDER`, P_C_NBR, P_C_DEPT, P_NUMBER, P_DASH, P_SORT, P_BIN, P_I_NUMBER, P_I_COLOR, P_UNIT, P_I_DEPT, P_COMM_COD, P_ASORT, P_CLASS,P_ASSEMBLY, P_PAY_CODE, P_PO_NBR, P_SLSM, P_TAXABLE, P_DISTRICT, P_CONTRACT, P_D_TYPE, P_HOLD, P_D_PER, P_A_COST, P_COST, P_PRICE, P_LIST, P_YY, P_MM, P_DD, P_O_TAKER, P_O_VER, P_O_PULLER, P_O_LOC, P_LOC, P_S_QUANTI, P_K_PRICE, P_STATE, P_INV_YY, P_INV_MM, P_INV_DD, P_NAME, P_O_QUANTI, P_B_QUANTI, P_ON_HAND, P_PO_NUMBE, P_PO_O_YY, P_PO_O_MM, P_PO_O_DD, P_PO_D_YY, P_PO_D_MM, P_PO_D_DD, P_DUE_YY, P_DUE_MM, P_DUE_DD, P_TERMINAL, P_STATUS, P_TYPE, P_TRASH, P_EXCEPT_1, P_EXCEPT_2, P_EXCEPT_3, P_EDI, P_TRANSMIT)" & _ " VALUES (@KEYS,@ORDER,@P_C_NBR,@P_C_DEPT,@P_NUMBER,@P_DASH,@P_SORT,@P_BIN,@P_I_NUMBER,@P_I_COLOR,@P_UNIT,@P_I_DEPT,@P_COMM_COD,@P_ASORT,@P_CLASS,@P_ASSEMBLY,@P_PAY_CODE,@P_PO_NBR,@P_SLSM,@P_TAXABLE,@P_DISTRICT,@P_CONTRACT,@P_D_TYPE,@P_HOLD,@P_D_PER,@P_A_COST,@P_COST,@P_PRICE,@P_LIST,@P_YY,@P_MM,@P_DD,@P_O_TAKER,@P_O_VER,@P_O_PULLER,@P_O_LOC,@P_LOC,@P_S_QUANTI,@P_K_PRICE,@P_STATE,@P_INV_YY,@P_INV_MM,@P_INV_DD,@P_NAME,@P_O_QUANTI,@P_B_QUANTI,@P_ON_HAND,@P_PO_NUMBE,@P_PO_O_YY,@P_PO_O_MM,@P_PO_O_DD,@P_PO_D_YY,@P_PO_D_MM,@P_PO_D_DD,@P_DUE_YY,@P_DUE_MM,@P_DUE_DD,@P_TERMINAL,@P_STATUS,@P_TYPE,@P_TRASH,@P_EXCEPT_1,@P_EXCEPT_2,@P_EXCEPT_3,@P_EDI,@P_TRANSMIT)", MyConn)
iCmd.Parameters.Add(New MySqlParameter("@KEYS", MySQLDbType.VarChar, 40, "KEYS")) iCmd.Parameters.Add(New MySqlParameter("@ORDER", MySQLDbType.VarChar, 20, "ORDER")) iCmd.Parameters.Add(New MySqlParameter("@P_C_NBR", MySQLDbType.VarChar, 10, "P_C_NBR")) iCmd.Parameters.Add(New MySqlParameter("@P_C_DEPT", MySQLDbType.VarChar, 4, "P_C_DEPT")) iCmd.Parameters.Add(New MySqlParameter("@P_NUMBER", MySQLDbType.VarChar, 8, "P_NUMBER")) iCmd.Parameters.Add(New MySqlParameter("@P_DASH", MySQLDbType.VarChar, 2, "P_DASH")) iCmd.Parameters.Add(New MySqlParameter("@P_SORT", MySQLDbType.VarChar, 3, "P_SORT")) iCmd.Parameters.Add(New MySqlParameter("@P_BIN", MySQLDbType.VarChar, 4, "P_BIN")) iCmd.Parameters.Add(New MySqlParameter("@P_I_NUMBER", MySQLDbType.VarChar, 15, "P_I_NUMBER")) iCmd.Parameters.Add(New MySqlParameter("@P_I_COLOR", MySQLDbType.VarChar, 8, "P_I_COLOR")) iCmd.Parameters.Add(New MySqlParameter("@P_UNIT", MySQLDbType.VarChar, 2, "P_UNIT")) iCmd.Parameters.Add(New MySqlParameter("@P_I_DEPT", MySQLDbType.VarChar, 1, "P_I_DEPT")) iCmd.Parameters.Add(New MySqlParameter("@P_COMM_COD", MySQLDbType.VarChar, 1, "P_COMM_COD")) iCmd.Parameters.Add(New MySqlParameter("@P_ASORT", MySQLDbType.VarChar, 4, "P_ASORT")) iCmd.Parameters.Add(New MySqlParameter("@P_CLASS", MySQLDbType.VarChar, 1, "P_CLASS")) iCmd.Parameters.Add(New MySqlParameter("@P_ASSEMBLY", MySQLDbType.VarChar, 1, "P_ASSEMBLY")) iCmd.Parameters.Add(New MySqlParameter("@P_PAY_CODE", MySQLDbType.VarChar, 1, "P_PAY_CODE")) iCmd.Parameters.Add(New MySqlParameter("@P_PO_NBR", MySQLDbType.VarChar, 10, "P_PO_NBR")) iCmd.Parameters.Add(New MySqlParameter("@P_SLSM", MySQLDbType.VarChar, 4, "P_SLSM")) iCmd.Parameters.Add(New MySqlParameter("@P_TAXABLE", MySQLDbType.VarChar, 1, "P_TAXABLE")) iCmd.Parameters.Add(New MySqlParameter("@P_DISTRICT", MySQLDbType.VarChar, 4, "P_DISTRICT")) iCmd.Parameters.Add(New MySqlParameter("@P_CONTRACT", MySQLDbType.VarChar, 2, "P_CONTRACT")) iCmd.Parameters.Add(New MySqlParameter("@P_D_TYPE", MySQLDbType.VarChar, 1, "P_D_TYPE")) iCmd.Parameters.Add(New MySqlParameter("@P_HOLD", MySQLDbType.VarChar, 1, "P_HOLD")) iCmd.Parameters.Add(New MySqlParameter("@P_D_PER", MySQLDbType.VarChar, 3, "P_D_PER")) iCmd.Parameters.Add(New MySqlParameter("@P_A_COST", MySQLDbType.VarChar, 10, "P_A_COST")) iCmd.Parameters.Add(New MySqlParameter("@P_COST", MySQLDbType.VarChar, 10, "P_COST")) iCmd.Parameters.Add(New MySqlParameter("@P_PRICE", MySQLDbType.VarChar, 10, "P_PRICE")) iCmd.Parameters.Add(New MySqlParameter("@P_LIST", MySQLDbType.VarChar, 10, "P_LIST")) iCmd.Parameters.Add(New MySqlParameter("@P_YY", MySQLDbType.VarChar, 2, "P_YY")) iCmd.Parameters.Add(New MySqlParameter("@P_MM", MySQLDbType.VarChar, 2, "P_MM")) iCmd.Parameters.Add(New MySqlParameter("@P_DD", MySQLDbType.VarChar, 2, "P_DD")) iCmd.Parameters.Add(New MySqlParameter("@P_O_TAKER", MySQLDbType.VarChar, 4, "P_O_TAKER")) iCmd.Parameters.Add(New MySqlParameter("@P_O_VER", MySQLDbType.VarChar, 4, "P_O_VER")) iCmd.Parameters.Add(New MySqlParameter("@P_O_PULLER", MySQLDbType.VarChar, 4, "P_O_PULLER")) iCmd.Parameters.Add(New MySqlParameter("@P_O_LOC", MySQLDbType.VarChar, 2, "P_O_LOC")) iCmd.Parameters.Add(New MySqlParameter("@P_LOC", MySQLDbType.VarChar, 2, "P_LOC")) iCmd.Parameters.Add(New MySqlParameter("@P_S_QUANTI", MySQLDbType.VarChar, 5, "P_S_QUANTI")) iCmd.Parameters.Add(New MySqlParameter("@P_K_PRICE", MySQLDbType.VarChar, 1, "P_K_PRICE")) iCmd.Parameters.Add(New MySqlParameter("@P_STATE", MySQLDbType.VarChar, 2, "P_STATE")) iCmd.Parameters.Add(New MySqlParameter("@P_INV_YY", MySQLDbType.VarChar, 2, "P_INV_YY")) iCmd.Parameters.Add(New MySqlParameter("@P_INV_MM", MySQLDbType.VarChar, 2, "P_INV_MM")) iCmd.Parameters.Add(New MySqlParameter("@P_INV_DD", MySQLDbType.VarChar, 2, "P_INV_DD")) iCmd.Parameters.Add(New MySqlParameter("@P_NAME", MySQLDbType.VarChar, 30, "P_NAME")) iCmd.Parameters.Add(New MySqlParameter("@P_O_QUANTI", MySQLDbType.VarChar, 5, "P_O_QUANTI")) iCmd.Parameters.Add(New MySqlParameter("@P_B_QUANTI", MySQLDbType.VarChar, 5, "P_B_QUANTI")) iCmd.Parameters.Add(New MySqlParameter("@P_ON_HAND", MySQLDbType.VarChar, 5, "P_ON_HAND")) iCmd.Parameters.Add(New MySqlParameter("@P_PO_NUMBE", MySQLDbType.VarChar, 10, "P_PO_NUMBE")) iCmd.Parameters.Add(New MySqlParameter("@P_PO_O_YY", MySQLDbType.VarChar, 2, "P_PO_O_YY")) iCmd.Parameters.Add(New MySqlParameter("@P_PO_O_MM", MySQLDbType.VarChar, 2, "P_PO_O_MM")) iCmd.Parameters.Add(New MySqlParameter("@P_PO_O_DD", MySQLDbType.VarChar, 2, "P_PO_O_DD")) iCmd.Parameters.Add(New MySqlParameter("@P_PO_D_YY", MySQLDbType.VarChar, 2, "P_PO_D_YY")) iCmd.Parameters.Add(New MySqlParameter("@P_PO_D_MM", MySQLDbType.VarChar, 2, "P_PO_D_MM")) iCmd.Parameters.Add(New MySqlParameter("@P_PO_D_DD", MySQLDbType.VarChar, 2, "P_PO_D_DD")) iCmd.Parameters.Add(New MySqlParameter("@P_DUE_YY", MySQLDbType.VarChar, 2, "P_DUE_YY")) iCmd.Parameters.Add(New MySqlParameter("@P_DUE_MM", MySQLDbType.VarChar, 2, "P_DUE_MM")) iCmd.Parameters.Add(New MySqlParameter("@P_DUE_DD", MySQLDbType.VarChar, 2, "P_DUE_DD")) iCmd.Parameters.Add(New MySqlParameter("@P_TERMINAL", MySQLDbType.VarChar, 2, "P_TERMINAL")) iCmd.Parameters.Add(New MySqlParameter("@P_STATUS", MySQLDbType.VarChar, 1, "P_STATUS")) iCmd.Parameters.Add(New MySqlParameter("@P_TYPE", MySQLDbType.VarChar, 1, "P_TYPE")) iCmd.Parameters.Add(New MySqlParameter("@P_TRASH", MySQLDbType.VarChar, 1, "P_TRASH")) iCmd.Parameters.Add(New MySqlParameter("@P_EXCEPT_1", MySQLDbType.VarChar, 1, "P_EXCEPT_1")) iCmd.Parameters.Add(New MySqlParameter("@P_EXCEPT_2", MySQLDbType.VarChar, 1, "P_EXCEPT_2")) iCmd.Parameters.Add(New MySqlParameter("@P_EXCEPT_3", MySQLDbType.VarChar, 1, "P_EXCEPT_3")) iCmd.Parameters.Add(New MySqlParameter("@P_EDI", MySQLDbType.VarChar, 1, "P_EDI")) iCmd.Parameters.Add(New MySqlParameter("@P_TRANSMIT", MySQLDbType.VarChar, 1, "P_TRANSMIT"))
MyDA.InsertCommand = iCmd
MyDA.Update(salesDS, "salejnls") Catch ex As Exception Console.Write(ex) End Try
Dim eTime As Date eTime = System.Date.Now
Dim dTime As Integer dTime = DateAndTime.DateDiff(DateInterval.Minute, sTime, eTime)
Console.WriteLine("There were " & salesDS.Tables("salejnls").Rows.Count() - 1 & " records created. In " & dTime & " minutes.") End Sub</color> <hr> I almost forgot to mention that this is a function in a custom class, which is being called by the console in a separate thread.
Code.. <hr> Dim uThread As Threading.Thread uThread = New Threading.Thread(New Threading.ThreadStart(AddressOf dJournals.UploadJournals)) uThread.Start() | | MigrationUser 1 Thursday, February 10, 2005 2:44 PM | Also, I'm not sure where I'm going wrong, but all of my rows in the MySQL Table are NULL. | | MigrationUser 1 Thursday, February 10, 2005 4:48 PM | Are there already records in the MySQL database before you begin this routine? You're calling:
MyDA.Fill(salesDS , "salejnls")
Which is going to fill SalesDS with all the records in the MySQL table. If there are already records in there, you are greatly increaing the number of rows that the Update method has to analyze. You should be calling MyDA.FillSchema becuase the schema of the table is all that salesDS needs.
I would really recommed that you create a fresh project and try this routine in as simple a manner as possible (no multi-threading, no custom classes). This will help determine the source of the problem. Also, you should create both data adapters at design time and let those adapters generate your datasets. The insert command generated by the data adapter configuration wizard may be faster than the one your wrote. Since you've only supplied the minimum properties to the DataAdpater for it to preform an update, it may be doing more work behind the scenes to make up for things you didn't configure.
Also be sure that MySQL is installed and configured properly. | | MigrationUser 1 Thursday, February 10, 2005 5:23 PM | Ok, I have gone back and created a very simple windows form application. It is a single form with one button and a datagrid to display the results. Instead of using the IEnumerator in a While Loop, I filled my dataset with the DataAdapter.AcceptChangesDuringFill set to False. I checked both the rowstate and information for the first row in the dataset and it is being filled and the rowstate is 4 or added. I'm still getting the same results though. Blank rows are being added to the MySQL Database. I would let Visual Studio create the connection for me, but it doesn't give you a wizard for the MySQL.Net connector.
Here is my new code. <hr> <color="Blue"> Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim vfSQL As String = "SELECT * FROM mysqltest" Dim conStr As String = "Provider=VFPOLEDB.1;DATA Source=Data;Mode=Share Deny None;Extended Properties=;Encrypt Password=False" Dim vfCon As New OleDb.OleDbConnection(conStr) Dim vfDA As New OleDb.OleDbDataAdapter(vfSQL, vfCon) Dim vfDS As New DataSet vfDA.AcceptChangesDuringFill = False vfDA.Fill(vfDS, "mysqltest")
Dim mSQL As String = "SELECT * FROM mysqltest" conStr = "Persist Security Info=False;database=DDMS;server=localhost;user id=manweb;Password=SQL4144mSs" Dim mCon As New MySql.Data.MySqlClient.MySqlConnection(conStr) Dim mDA As New MySql.Data.MySqlClient.MySqlDataAdapter(mSQL, mCon) Dim iCmd As MySql.Data.MySqlClient.MySqlCommand iCmd = New MySql.Data.MySqlClient.MySqlCommand("INSERT INTO mysqltest(`fName`, `lName`, `Address`, `City`, `zip`, `state`) VALUE (@fName, @lName, @Address, @City, @Zip, @State)", mCon) iCmd.Parameters.Add(New MySql.Data.MySqlClient.MySqlParameter("@fName", MySql.Data.MySqlClient.MySqlDbType.VarChar, 10, "fName")) iCmd.Parameters.Add(New MySql.Data.MySqlClient.MySqlParameter("@lName", MySql.Data.MySqlClient.MySqlDbType.VarChar, 10, "lName")) iCmd.Parameters.Add(New MySql.Data.MySqlClient.MySqlParameter("@Address", MySql.Data.MySqlClient.MySqlDbType.VarChar, 30, "Address")) iCmd.Parameters.Add(New MySql.Data.MySqlClient.MySqlParameter("@City", MySql.Data.MySqlClient.MySqlDbType.VarChar, 10, "City")) iCmd.Parameters.Add(New MySql.Data.MySqlClient.MySqlParameter("@Zip", MySql.Data.MySqlClient.MySqlDbType.Int16, 5, "Zip")) iCmd.Parameters.Add(New MySql.Data.MySqlClient.MySqlParameter("@state", MySql.Data.MySqlClient.MySqlDbType.VarChar, 2, "state")) mDA.InsertCommand = iCmd
MessageBox.Show(vfDS.Tables("mysqltest").Rows(0).RowState()) mDA.Update(vfDS, "mysqltest")
Dim myDS As New DataSet mDA.Fill(myDS, "mysqltest")
Me.DataGrid1.DataSource = myDS.Tables("mysqltest") End Sub </color> | | MigrationUser 1 Friday, February 11, 2005 9:50 AM | I'm not sure what to tell you here... If you are getting blank rows then your parameters must be empty when the Insert command executes.
I did misunderstand what database you were using, sorry. I have no experience with the MySQL product... but it sounds like your problem is with MySQL, not .NET Data Access.
What you are doing should work if they Insert command is written properly and the source and destination tables are identical.
I'd find a MySQL guru to analyze your Insert command, database design, and database configuration... or switch to SQL Desktop (MSDE) or SQL Server and let .NET Data Access work for you.
Sorry I can't help. | | MigrationUser 1 Friday, February 11, 2005 1:03 PM | Thanks for all the help anyways rkimble. If you think of anything please let me know. I'll post on MySQL's site and see if I can get any response there. If I find a solution I'll post it back here.
Thanks Again!! | | MigrationUser 1 Friday, February 11, 2005 1:07 PM | Hey, I did think of one other possible thing...
Look up the DataAdapter Class on the MSDN library... I seem to remeber something about the various Commands working together... Your parameters may all be empty becuase you don't have a matching Select Command to gather those parameters. Don't quote me on this; I don't entirely remeber what that article said about the internal workings of the DataAdapter... but I do think it is possible that you just need a more well defined DataAdapter to do your update.
...I suppose if something like this is happening, it could also account for the time it is taking... the DataAdapter may be trying several different routines on each field to try to come up with a value and only when all of them fail does it finally settle for Null... that's just more conjecture though...
Anyway, you're welcome for whatever was useful! If you get a hard answer from someone on another forum I would definately apprieciate the post back here. You've got me curious to know what's happening. =)
Good luck! | | MigrationUser 1 Friday, February 11, 2005 4:01 PM | Ok I figured it out by searching through mysql.com's forum posts. The proper syntax for the insert statement under the .net connector now uses "?" instead of "@". So the insert statement now looks like this.
("INSERT INTO tablename (`item1`,`item2`) VALUES (?item1,?item2)", mCon)
As far as speed it is still pretty slow. I figure at the rate it is inserting records it will take about 3½ hours. I'll look into the DataAdapter more.
Thanks Again. | | MigrationUser 1 Friday, February 11, 2005 4:49 PM |
|