SQLCE database Insertion error

  • Thread starter Thread starter micmic
  • Start date Start date
M

micmic

dear all expert,
My programme is as follows:


try
{
conn = new SqlCeConnection ("Data Source = POS.sdf");

conn.Open();

cmd = conn.CreateCommand();
cmd.CommandText = "INSERT INTO tbl_Check (A,B) VALUES (?,?) ";

cmd.Parameters.Add("A", SqlDbType.Int).Value = check.CheckNo;
cmd.Parameters.Add("B", SqlDbType.NVarChar,15).Value = check.Date;

cmd.Prepare();

int success = cmd.ExecuteNonQuery();
}
catch( )
{
....................

}

where the table is
A Int
B NVarChar(15)


When i run the programme , there is error in the line

int success = cmd.ExecuteNonQuery();

and then error message code is :
An unhandled exception of type 'System.NullReferenceException' occurred in
System.Data.SqlServerCe.dll

Additional information: B


Why such case happens for string case? If B is a int, then it will work
fine.

Best wishes,
Michael
 
Back
Top