Forum Discussion

MishaMisha's avatar
14 years ago

Error with assigning OleDbCommand.Parameter

Hello,



The last line of following C# Script code:



 var con = dotNET["System_Data_OleDb"]["OleDbConnection"]["zctor"]("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\\mydb.accdb");

 con.Open();



  cmd.CommandText = "INSERT INTO [Users](ID,Nickname) VALUES( @id, @nick)";

  cmd.Parameters.Add("id", 3);

  cmd.Parameters.Add("nick", 202);

  cmd.Parameters["id"].Value = 0;



Fails with 'Parameters.id is null or not an object' error. How do I set the value?



//Misha
  • AlexKaras's avatar
    AlexKaras
    Champion Level 3
    Hi Misha,



    Not sure whether this will help, but try this:

    cmd.Parameters["id"].Value = VarToInt(0);