Hi,
I am working in an application in VB.NET. I got stuck in this ERROR:
System.NotSupportedException
HResult=0x80131515
Message=The member ClientId of type BillTimeLibrary.BillTimeLibrary.Models.ClientModel cannot be used as a parameter value
Contextualizing...
First, I have this same application working in C#. I am converting to VB.NET to learn and understand how to use SQLite Database with Dapper with these both languages.
The error appears in the pass-through of a parameter from a sub routine that connects two tables from my database.
The Payments table has a Foreing Key named ClientId, which identifies which client the payment is from. In the payments window I have a Combobox where I choose the client, and if there is any payment already made the dates of the payments is listed in another Combobox.
That query is not working, when I choose the client the program should fetch the Payments in the Tablet Payments by the ClientId, but it gives that error that I mentioned above.
The subroutine that should pass the parameters for query is:
Private Sub LoadDateDropDown()
Dim sql As String = "select * from Payment where ClientId = @ClientId"
Dim parameters As Dictionary(Of String, Object) = New Dictionary(Of String, Object) From {
{"@ClientId", ClientDropDown.SelectedValue}
}
Dim records = SQLiteDataAccess.LoadData(Of PaymentsModel)(sql, parameters)
payments.Clear()
records.ForEach(Sub(x) payments.Add(x))
End Sub
the message is viewed in the Load Sub which receives the parameters.
The parameter it is mentioned in the message is created in a Model: it has the same type of variable used in the Database Table.
Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Text
Imports System.Threading.Tasks
Namespace BillTimeLibrary.Models
Public Class PaymentsModel
Public Property Id As Integer
Public Property ClientId As Integer
Public Property Hours As Double
Public Property Amount As Double
Public Property DatePayment As String
End Class
End Namespace
I think I might be using the wrong property of the ClientDropDown (my combobox)
See the original code in the C#:
private void LoadDateDropDown()
{
string sql = "select * from Payment where ClientId = @ClientId";
Dictionary<string, object> parameters = new Dictionary<string, object>
{
{ "@ClientId", ClientDropDown.SelectedValue }
};
var records = SQLiteDataAccess.LoadData<PaymentsModel>(sql, parameters);
payments.Clear();
records.ForEach(x => payments.Add(x));
}
What I have tried:
I am trying to see how to access the payments table through the ClientId Field. No success yet.
This is the FULL Details about the error.. it seems to be something with Dapper. But As I am new with it I do not know how to solve yet.
System.NotSupportedException
HResult=0x80131515
Message=The member ClientId of type BillTimeLibrary.BillTimeLibrary.Models.ClientModel cannot be used as a parameter value
Source=Dapper
StackTrace:
at Dapper.SqlMapper.LookupDbType(Type type, String name, Boolean demand, ITypeHandler& handler) in C:\projects\dapper\Dapper\SqlMapper.cs:line 417
at Dapper.DynamicParameters.AddParameters(IDbCommand command, Identity identity) in C:\projects\dapper\Dapper\DynamicParameters.cs:line 238
at Dapper.DynamicParameters.Dapper.SqlMapper.IDynamicParameters.AddParameters(IDbCommand command, Identity identity) in C:\projects\dapper\Dapper\DynamicParameters.cs:line 156
at Dapper.SqlMapper.<>c__DisplayClass161_0.<getcacheinfo>b__0(IDbCommand cmd, Object obj) in C:\projects\dapper\Dapper\SqlMapper.cs:line 1694
at Dapper.CommandDefinition.SetupCommand(IDbConnection cnn, Action`2 paramReader) in C:\projects\dapper\Dapper\CommandDefinition.cs:line 128
at Dapper.SqlMapper.<queryimpl>d__138`1.MoveNext() in C:\projects\dapper\Dapper\SqlMapper.cs:line 1075
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
at Dapper.SqlMapper.Query[T](IDbConnection cnn, String sql, Object param, IDbTransaction transaction, Boolean buffered, Nullable`1 commandTimeout, Nullable`1 commandType) in C:\projects\dapper\Dapper\SqlMapper.cs:line 723
at BillTimeLibrary.SQLiteDataAccess.LoadData[T](String sqlStatement, Dictionary`2 parameters, String connectionName) in C:\BillTime_VB\BillTimeLibrary\DataAccess\SQLiteDataAccess.vb:line 25
at BillTime_VB.Payments.LoadDateDropDown() in C:\BillTime_VB\BillTime_VB\Controls\Payments.vb:line 141
at BillTime_VB.Payments.ClientDropDown_SelectedIndexChanged(Object sender, EventArgs e) in C:\BillTime_VB\BillTime_VB\Controls\Payments.vb:line 133
at System.Windows.Forms.ComboBox.OnSelectedIndexChanged(EventArgs e)
at System.Windows.Forms.ComboBox.set_SelectedIndex(Int32 value)
at System.Windows.Forms.ComboBox.RefreshItems()
at System.Windows.Forms.ComboBox.OnDataSourceChanged(EventArgs e)
at System.Windows.Forms.ListControl.SetDataConnection(Object newDataSource, BindingMemberInfo newDisplayMember, Boolean force)
at System.Windows.Forms.ListControl.set_DataSource(Object value)