I want to change the below C# code from ordinary SQL to a stored procedure but it always show error on columns that they are Invalid Column. What is wrong with the stored procedure?
CREATE PROCEDURE [dbo].[usp_AdminRegPage1]
(@VendorId VARCHAR)
AS
BEGIN
SET NOCOUNT ON;
SELECT WorksPackage,MajorWorks FROM dbo.RegPage1 WHERE Vendor_Id = @VendorId;
END
protected void DisplayRecord()
{
SqlConnection SqlCon = new SqlConnection(GetConnectionString());
string sql = "SELECT WorksPackage,MajorWorks from RegPage1
WHERE Vendor_ID='"+lblPage1ID.Text+"'";
var da = new SqlDataAdapter(sql, SqlCon);
var ds = new DataSet();
da.Fill(ds);
if (ds.Tables[0].Rows.Count > 0)
{
txtMajorPackages.Text = ds.Tables[0].Rows[0]["WorksPackage"].ToString();
txtRegP1Works.Text = ds.Tables[0].Rows[0]["MajorWorks"].ToString();
}
}
Something like this should do the job
Example taken from this website
http://www.csharp-station.com/Tutorials/AdoDotNet/Lesson07.aspx