Error in Visual Studio C# | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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

10th Sep 2020, 10:33 AM
Radendy Bahtiar
Radendy Bahtiar - avatar
2 Answers
+ 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; }
10th Sep 2020, 5:01 PM
hossein B
hossein B - avatar
+ 1
If the problem is not solved, I am waiting for Your further description
10th Sep 2020, 5:03 PM
hossein B
hossein B - avatar