Problem Adding Rows with TIMESTAMP
Posted: Tue 07 Mar 2006 17:18
I'm using VS 2005 (VB), MySQLDirect .NET 3.50 beta, MySQL 5.0 server.
In my code I create a MySQLTableAdapter with this code:
Dim prodPositionTable As MySqlDataTable = New MySqlDataTable("SELECT * FROM mm_options.positions", "User ID=haldi;Password=XXXXXXX;Host=XXXXXXXX;Database=mm_options")
prodPositionTable.Active = True
I then go through another table and try to add rows to the prodPositionTable with this code:
Dim GSECRow As DataRow
For Each GSECRow In GSECPositionUpload.Rows
Dim newProdRow As DataRow = prodPositionTable.NewRow
newProdRow("account") = Mid(GSECRow.Item("ACCOUNT_NUMBER_ENTITY_ID"), 1, 4)
newProdRow("product") = GSECRow.Item("BASIC_PRODUCT")
newProdRow("und_symbol") = GSECRow.Item("UNDERLYING_SYMBOL")
If GSECRow.Item("EXPIRATION_YEAR") "" Then
newProdRow("expiry") = GSECRow.Item("EXPIRATION_MONTH") & "/" & GSECRow.Item("EXPIRATION_DAY") & "/" & GSECRow.Item("EXPIRATION_YEAR")
newProdRow("strike") = GSECRow.Item("STRIKE_PRICE")
newProdRow("put_call") = GSECRow.Item("PUT_CALL")
End If
newProdRow("multiplier") = GSECRow.Item("MULTIPLIER")
newProdRow("open_quantity") = GSECRow.Item("T_D_QUANTITY")
newProdRow("curr_quantity") = GSECRow.Item("T_D_QUANTITY")
newProdRow("option_wrap") = GSECRow.Item("TRADING_SYMBOL")
newProdRow("opra_code") = GSECRow.Item("OPRA_CODE")
newProdRow("timestamp") = Today.n
prodPositionTable.Rows.Add(newProdRow)
ProgressBar1.Value = ProgressBar1.Value + 1
Next
When the code gets to the prodPositionTable.Rows.Add(newProdRow), it throws an exception saying that 'timestamp' field can not be set to null.
In the actual table, timestamp is set to allow nulls, and to default to the value of CURRENT_TIMESTAMP.
If I use the DBMonitor tool, I see that the exception isn't being thrown by MySQL - the command never gets passed. Rather it is being thrown by something on the client side. As you can see, I don't set the TIMESTAMP value to anything in my code (I don't want to - I want the DB to do it automatically).
Can anybody please help me sort this out?
Many thanks,
John Haldi
[email protected]
In my code I create a MySQLTableAdapter with this code:
Dim prodPositionTable As MySqlDataTable = New MySqlDataTable("SELECT * FROM mm_options.positions", "User ID=haldi;Password=XXXXXXX;Host=XXXXXXXX;Database=mm_options")
prodPositionTable.Active = True
I then go through another table and try to add rows to the prodPositionTable with this code:
Dim GSECRow As DataRow
For Each GSECRow In GSECPositionUpload.Rows
Dim newProdRow As DataRow = prodPositionTable.NewRow
newProdRow("account") = Mid(GSECRow.Item("ACCOUNT_NUMBER_ENTITY_ID"), 1, 4)
newProdRow("product") = GSECRow.Item("BASIC_PRODUCT")
newProdRow("und_symbol") = GSECRow.Item("UNDERLYING_SYMBOL")
If GSECRow.Item("EXPIRATION_YEAR") "" Then
newProdRow("expiry") = GSECRow.Item("EXPIRATION_MONTH") & "/" & GSECRow.Item("EXPIRATION_DAY") & "/" & GSECRow.Item("EXPIRATION_YEAR")
newProdRow("strike") = GSECRow.Item("STRIKE_PRICE")
newProdRow("put_call") = GSECRow.Item("PUT_CALL")
End If
newProdRow("multiplier") = GSECRow.Item("MULTIPLIER")
newProdRow("open_quantity") = GSECRow.Item("T_D_QUANTITY")
newProdRow("curr_quantity") = GSECRow.Item("T_D_QUANTITY")
newProdRow("option_wrap") = GSECRow.Item("TRADING_SYMBOL")
newProdRow("opra_code") = GSECRow.Item("OPRA_CODE")
newProdRow("timestamp") = Today.n
prodPositionTable.Rows.Add(newProdRow)
ProgressBar1.Value = ProgressBar1.Value + 1
Next
When the code gets to the prodPositionTable.Rows.Add(newProdRow), it throws an exception saying that 'timestamp' field can not be set to null.
In the actual table, timestamp is set to allow nulls, and to default to the value of CURRENT_TIMESTAMP.
If I use the DBMonitor tool, I see that the exception isn't being thrown by MySQL - the command never gets passed. Rather it is being thrown by something on the client side. As you can see, I don't set the TIMESTAMP value to anything in my code (I don't want to - I want the DB to do it automatically).
Can anybody please help me sort this out?
Many thanks,
John Haldi
[email protected]