0
Error in Visual Studio C#
I have a variable inside HttpGet actionresult. It contains a syntax to call SP from SQL Server with user input parameter, i use DbRawSqlQuery. This is my SP (in SQL Server): SELECT TOP 1 COLUMN FROM TABLE etc... It works fine when i run it in SQL. But it gets error in visual studio (its return value) When i use this SP: SELECT * FROM TABLE etc.. It works fine in both applications Can anyone do me a favor? Thanks
2 Réponses
+ 1
Hi bro, i cant understand your problem. For more help, please send your code and error number
This is one example to get one column from sql
static public int AddProductCategory(string newName, string connString)
{
Int32 newProdID = 0;
string sql =
"INSERT INTO Production.ProductCategory (Name) VALUES (@Name); "
+ "SELECT CAST(scope_identity() AS int)";
using (SqlConnection conn = new SqlConnection(connString))
{
SqlCommand cmd = new SqlCommand(sql, conn);
cmd.Parameters.Add("@Name", SqlDbType.VarChar);
cmd.Parameters["@name"].Value = newName;
try
{
conn.Open();
newProdID = (Int32)cmd.ExecuteScalar();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
return (int)newProdID;
}
+ 1
If the problem is not solved, I am waiting for Your further description