Problem is :
My query
INSERT INTO TableName(val1,val2)values(1,2);
SELECT @@IDENTITY;
When I run it in run query from server explorer I get the correct result.
But when I use ExecuteScalar
or ExecuteDataTable
I get an error ,... query return null
public object ExecuteScalre(string Query, CommandType type)
{
OpenConnection();
cmd.CommandText = Query;
cmd.CommandType = type;
object obj = null;
try
{
obj = cmd.ExecuteScalar();
}
catch
{
}
finally
{
ReleaseResource();
}
return obj;
}
public DataTable ExecuteDataTable(string Query, CommandType type)
{
OpenConnection();
cmd.CommandText = Query;
cmd.CommandType = type;
DataTable dt = new DataTable();
dataAdaptor = new SqlCeDataAdapter(cmd);
try
{
dataAdaptor.Fill(dt);
}
catch
{
}
finally
{
ReleaseResource();
}
return dt;
}
Notes: it's an .sdf
file (SQL Server CE), NOT .mdf
, so we can not use stored procedures