Here is my code but it returns -1 value. The Name field contains a unicode value.
using (SqlConnection conn = new SqlConnection(connStr))
{
string str = string.Format("select SrNo from Jat where Name=@Name");
SqlCommand dCmd = new SqlCommand(str, conn);
try
{
dCmd.Parameters.AddWithValue("@Name","N" +Name);
int i= dCmd.ExecuteNonQuery();
return i;
}
catch
{
throw;
}
}
there is no need to write down
remove “N” from this but it doesnt create nvarchar parameter
To create nvarchar type parameter than you can do this
this will create nvarchar parameter than you can add this parameter as nvarchar parameter
one more change in code is make use of ExecuteScalar
make use of ExecuteScalar method rather than ExecuteNonQuey ….becuase non Sclar method return value of you SrNo and NonQuery return you row affected when using update and insert query