Getting return value from stored procedure in ADO.NET

前端 未结 5 1524
感动是毒
感动是毒 2020-12-09 03:43

I know that there is another question with nearly the same title, but it doesn\'t answer my question. I have a stored procedure, which returns the unique identifier after in

5条回答
  •  难免孤独
    2020-12-09 04:39

    you can use standart ways that you use before in normal queries but in Sql command you must write EXEC before your store procedure name and dont use commandtype like this :

     SqlConnection con = new SqlConnection(["ConnectionString"])
        SqlCommand com = new SqlCommand("EXEC _Proc @id",con);
        com.Parameters.AddWithValue("@id",["IDVALUE"]);
        con.Open();
        SqlDataReader rdr = com.ExecuteReader();
        ArrayList liste = new ArrayList();
        While(rdr.Read())
        {
        liste.Add(rdr[0]); //if it returns multiple you can add them another arrays=> liste1.Add(rdr[1]) ..
        }
        con.Close();
    

提交回复
热议问题