E
evint
Has anyone tried using Microsoft's ADO.NET DataAdapter Builder? This
tool is included on the companion CD to the book Microsoft ADO.NET Core
Reference (Microsoft Press, David Sceppa, ISBN 0-7356-1423-7).
I used it to generate the DataAdapter code for my app but I am not sure
what to do with the code it generated. This may be a very useful
(unsupported) tool, but the jury is still out. I cut and pasted the
generated code into my app but I am getting an 'Error 8 Overload
resolution failed because no accessible 'New' can be called without a
narrowing conversion' message for each cmd.Parameters.Add line. Setting
Option Strict Off has no effect. Any suggestions on implementing it?
Thanks,
Vint
<DATAADAPTER BUILDER CODE>
Imports System.Data
Imports System.Data.OleDb
Private Function CreateDataAdapter() As OleDbDataAdapter
Dim da As New OleDbDataAdapter("SELECT [Batch.Batch Key],
[Batch.Comments], [Batch.Is Active], [Batch.Is Pre Entered] FROM BATCH
where [Batch.Batch Key] = 4643", _
"Provider=Microsoft.Jet.OLEDB.4.0;
Data Source=C:\gfpc\resin\gfpc.mdb")
Dim dtm As Common.DataTableMapping
dtm = da.TableMappings.Add("Table", "BATCH")
dtm.ColumnMappings.Add("Batch.Batch Key", "Batch.Batch Key")
dtm.ColumnMappings.Add("Batch.Comments", "Batch.Comments")
dtm.ColumnMappings.Add("Batch.Is Active", "Batch.Is Active")
dtm.ColumnMappings.Add("Batch.Is Pre Entered", "Batch.Is Pre
Entered")
Dim cmd As OleDbCommand
da.UpdateCommand = da.SelectCommand.Connection.CreateCommand()
cmd = da.UpdateCommand
cmd.UpdatedRowSource = UpdateRowSource.None
cmd.CommandText = "UPDATE `BATCH` SET `Comments` = ?, `Is Active` =
?, `Is Pre Entered` = ? WHERE `Batch Key` = ? AND (`Is Active` = ? OR
((`Is Active` IS NULL) AND (? IS NULL))) AND (`Is Pre Entered` = ? OR
((`Is Pre Entered` IS NULL) AND (? IS NULL)))"
cmd.Parameters.Add(New OleDbParameter("@CommentsCurrent",
OleDbType.LongVarWChar, 536870910, ParameterDirection.Input, True, 0,
0, "Batch.Comments", DataRowVersion.Current, Nothing))
cmd.Parameters.Add(New OleDbParameter("@Is ActiveCurrent",
OleDbType.Boolean, 2, ParameterDirection.Input, True, 0, 0, "Batch.Is
Active", DataRowVersion.Current, Nothing))
cmd.Parameters.Add(New OleDbParameter("@Is Pre EnteredCurrent",
OleDbType.Boolean, 2, ParameterDirection.Input, True, 0, 0, "Batch.Is
Pre Entered", DataRowVersion.Current, Nothing))
cmd.Parameters.Add(New OleDbParameter("@Batch KeyOriginal",
OleDbType.Integer, 4, ParameterDirection.Input, False, 10, 0,
"Batch.Batch Key", DataRowVersion.Original, Nothing))
cmd.Parameters.Add(New OleDbParameter("@Is ActiveOriginal",
OleDbType.Boolean, 2, ParameterDirection.Input, True, 0, 0, "Batch.Is
Active", DataRowVersion.Original, Nothing))
cmd.Parameters.Add(New OleDbParameter("@Is ActiveNullCheck",
OleDbType.Boolean, 2, ParameterDirection.Input, True, 0, 0, "Batch.Is
Active", DataRowVersion.Original, Nothing))
cmd.Parameters.Add(New OleDbParameter("@Is Pre EnteredOriginal",
OleDbType.Boolean, 2, ParameterDirection.Input, True, 0, 0, "Batch.Is
Pre Entered", DataRowVersion.Original, Nothing))
cmd.Parameters.Add(New OleDbParameter("@Is Pre EnteredNullCheck",
OleDbType.Boolean, 2, ParameterDirection.Input, True, 0, 0, "Batch.Is
Pre Entered", DataRowVersion.Original, Nothing))
da.InsertCommand = da.SelectCommand.Connection.CreateCommand()
cmd = da.InsertCommand
cmd.UpdatedRowSource = UpdateRowSource.None
cmd.CommandText = "INSERT INTO `BATCH` (`Comments`, `Is Active`,
`Is Pre Entered`) VALUES (?, ?, ?)"
cmd.Parameters.Add(New OleDbParameter("@CommentsCurrent",
OleDbType.LongVarWChar, 536870910, ParameterDirection.Input, True, 0,
0, "Batch.Comments", DataRowVersion.Current, Nothing))
cmd.Parameters.Add(New OleDbParameter("@Is ActiveCurrent",
OleDbType.Boolean, 2, ParameterDirection.Input, True, 0, 0, "Batch.Is
Active", DataRowVersion.Current, Nothing))
cmd.Parameters.Add(New OleDbParameter("@Is Pre EnteredCurrent",
OleDbType.Boolean, 2, ParameterDirection.Input, True, 0, 0, "Batch.Is
Pre Entered", DataRowVersion.Current, Nothing))
da.DeleteCommand = da.SelectCommand.Connection.CreateCommand()
cmd = da.DeleteCommand
cmd.UpdatedRowSource = UpdateRowSource.None
cmd.CommandText = "DELETE FROM `BATCH` WHERE `Batch Key` = ? AND
(`Is Active` = ? OR ((`Is Active` IS NULL) AND (? IS NULL))) AND (`Is
Pre Entered` = ? OR ((`Is Pre Entered` IS NULL) AND (? IS NULL)))"
cmd.Parameters.Add(New OleDbParameter("@Batch KeyOriginal",
OleDbType.Integer, 4, ParameterDirection.Input, False, 10, 0,
"Batch.Batch Key", DataRowVersion.Original, Nothing))
cmd.Parameters.Add(New OleDbParameter("@Is ActiveOriginal",
OleDbType.Boolean, 2, ParameterDirection.Input, True, 0, 0, "Batch.Is
Active", DataRowVersion.Original, Nothing))
cmd.Parameters.Add(New OleDbParameter("@Is ActiveNullCheck",
OleDbType.Boolean, 2, ParameterDirection.Input, True, 0, 0, "Batch.Is
Active", DataRowVersion.Original, Nothing))
cmd.Parameters.Add(New OleDbParameter("@Is Pre EnteredOriginal",
OleDbType.Boolean, 2, ParameterDirection.Input, True, 0, 0, "Batch.Is
Pre Entered", DataRowVersion.Original, Nothing))
cmd.Parameters.Add(New OleDbParameter("@Is Pre EnteredNullCheck",
OleDbType.Boolean, 2, ParameterDirection.Input, True, 0, 0, "Batch.Is
Pre Entered", DataRowVersion.Original, Nothing))
Return da
End Function
</DATAADAPTER BUILDER CODE>
tool is included on the companion CD to the book Microsoft ADO.NET Core
Reference (Microsoft Press, David Sceppa, ISBN 0-7356-1423-7).
I used it to generate the DataAdapter code for my app but I am not sure
what to do with the code it generated. This may be a very useful
(unsupported) tool, but the jury is still out. I cut and pasted the
generated code into my app but I am getting an 'Error 8 Overload
resolution failed because no accessible 'New' can be called without a
narrowing conversion' message for each cmd.Parameters.Add line. Setting
Option Strict Off has no effect. Any suggestions on implementing it?
Thanks,
Vint
<DATAADAPTER BUILDER CODE>
Imports System.Data
Imports System.Data.OleDb
Private Function CreateDataAdapter() As OleDbDataAdapter
Dim da As New OleDbDataAdapter("SELECT [Batch.Batch Key],
[Batch.Comments], [Batch.Is Active], [Batch.Is Pre Entered] FROM BATCH
where [Batch.Batch Key] = 4643", _
"Provider=Microsoft.Jet.OLEDB.4.0;
Data Source=C:\gfpc\resin\gfpc.mdb")
Dim dtm As Common.DataTableMapping
dtm = da.TableMappings.Add("Table", "BATCH")
dtm.ColumnMappings.Add("Batch.Batch Key", "Batch.Batch Key")
dtm.ColumnMappings.Add("Batch.Comments", "Batch.Comments")
dtm.ColumnMappings.Add("Batch.Is Active", "Batch.Is Active")
dtm.ColumnMappings.Add("Batch.Is Pre Entered", "Batch.Is Pre
Entered")
Dim cmd As OleDbCommand
da.UpdateCommand = da.SelectCommand.Connection.CreateCommand()
cmd = da.UpdateCommand
cmd.UpdatedRowSource = UpdateRowSource.None
cmd.CommandText = "UPDATE `BATCH` SET `Comments` = ?, `Is Active` =
?, `Is Pre Entered` = ? WHERE `Batch Key` = ? AND (`Is Active` = ? OR
((`Is Active` IS NULL) AND (? IS NULL))) AND (`Is Pre Entered` = ? OR
((`Is Pre Entered` IS NULL) AND (? IS NULL)))"
cmd.Parameters.Add(New OleDbParameter("@CommentsCurrent",
OleDbType.LongVarWChar, 536870910, ParameterDirection.Input, True, 0,
0, "Batch.Comments", DataRowVersion.Current, Nothing))
cmd.Parameters.Add(New OleDbParameter("@Is ActiveCurrent",
OleDbType.Boolean, 2, ParameterDirection.Input, True, 0, 0, "Batch.Is
Active", DataRowVersion.Current, Nothing))
cmd.Parameters.Add(New OleDbParameter("@Is Pre EnteredCurrent",
OleDbType.Boolean, 2, ParameterDirection.Input, True, 0, 0, "Batch.Is
Pre Entered", DataRowVersion.Current, Nothing))
cmd.Parameters.Add(New OleDbParameter("@Batch KeyOriginal",
OleDbType.Integer, 4, ParameterDirection.Input, False, 10, 0,
"Batch.Batch Key", DataRowVersion.Original, Nothing))
cmd.Parameters.Add(New OleDbParameter("@Is ActiveOriginal",
OleDbType.Boolean, 2, ParameterDirection.Input, True, 0, 0, "Batch.Is
Active", DataRowVersion.Original, Nothing))
cmd.Parameters.Add(New OleDbParameter("@Is ActiveNullCheck",
OleDbType.Boolean, 2, ParameterDirection.Input, True, 0, 0, "Batch.Is
Active", DataRowVersion.Original, Nothing))
cmd.Parameters.Add(New OleDbParameter("@Is Pre EnteredOriginal",
OleDbType.Boolean, 2, ParameterDirection.Input, True, 0, 0, "Batch.Is
Pre Entered", DataRowVersion.Original, Nothing))
cmd.Parameters.Add(New OleDbParameter("@Is Pre EnteredNullCheck",
OleDbType.Boolean, 2, ParameterDirection.Input, True, 0, 0, "Batch.Is
Pre Entered", DataRowVersion.Original, Nothing))
da.InsertCommand = da.SelectCommand.Connection.CreateCommand()
cmd = da.InsertCommand
cmd.UpdatedRowSource = UpdateRowSource.None
cmd.CommandText = "INSERT INTO `BATCH` (`Comments`, `Is Active`,
`Is Pre Entered`) VALUES (?, ?, ?)"
cmd.Parameters.Add(New OleDbParameter("@CommentsCurrent",
OleDbType.LongVarWChar, 536870910, ParameterDirection.Input, True, 0,
0, "Batch.Comments", DataRowVersion.Current, Nothing))
cmd.Parameters.Add(New OleDbParameter("@Is ActiveCurrent",
OleDbType.Boolean, 2, ParameterDirection.Input, True, 0, 0, "Batch.Is
Active", DataRowVersion.Current, Nothing))
cmd.Parameters.Add(New OleDbParameter("@Is Pre EnteredCurrent",
OleDbType.Boolean, 2, ParameterDirection.Input, True, 0, 0, "Batch.Is
Pre Entered", DataRowVersion.Current, Nothing))
da.DeleteCommand = da.SelectCommand.Connection.CreateCommand()
cmd = da.DeleteCommand
cmd.UpdatedRowSource = UpdateRowSource.None
cmd.CommandText = "DELETE FROM `BATCH` WHERE `Batch Key` = ? AND
(`Is Active` = ? OR ((`Is Active` IS NULL) AND (? IS NULL))) AND (`Is
Pre Entered` = ? OR ((`Is Pre Entered` IS NULL) AND (? IS NULL)))"
cmd.Parameters.Add(New OleDbParameter("@Batch KeyOriginal",
OleDbType.Integer, 4, ParameterDirection.Input, False, 10, 0,
"Batch.Batch Key", DataRowVersion.Original, Nothing))
cmd.Parameters.Add(New OleDbParameter("@Is ActiveOriginal",
OleDbType.Boolean, 2, ParameterDirection.Input, True, 0, 0, "Batch.Is
Active", DataRowVersion.Original, Nothing))
cmd.Parameters.Add(New OleDbParameter("@Is ActiveNullCheck",
OleDbType.Boolean, 2, ParameterDirection.Input, True, 0, 0, "Batch.Is
Active", DataRowVersion.Original, Nothing))
cmd.Parameters.Add(New OleDbParameter("@Is Pre EnteredOriginal",
OleDbType.Boolean, 2, ParameterDirection.Input, True, 0, 0, "Batch.Is
Pre Entered", DataRowVersion.Original, Nothing))
cmd.Parameters.Add(New OleDbParameter("@Is Pre EnteredNullCheck",
OleDbType.Boolean, 2, ParameterDirection.Input, True, 0, 0, "Batch.Is
Pre Entered", DataRowVersion.Original, Nothing))
Return da
End Function
</DATAADAPTER BUILDER CODE>