Is there a way when clicked on a button in a C# Windows App, that it can fire off a store开发者_Python百科d procedure to update data? Im also having issues seeing the SP in my data sources, first time this has ever happened to me. Amy ideas on these things? Should I use an SSIS instead, is that even possible?
Thanks
ALTER PROCEDURE dbo.InsertData
@QuoteNumber as varchar(11),
@ItemNumber as varchar(15)
AS
UPDATE SF1411
SET QuoteNumber = @QuoteNumber, ItemNumber = @ItemNumber, DeleteItem = 'NO'
WHERE (QuoteNumber IS NULL)
RETURN
I think it's something like this...
using (SqlCommand cmd = new SqlCommand("InsertData", conn))
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(new SqlParameter("@QuoteNumber ", QuoteNumber ));
cmd.Parameters.Add(new SqlParameter("@ItemNumber ", ItemNumber ));
cmd.ExecuteNonQuery();
}
shin's answer looks ok. although i dont think you have to write "new sql parameter".
it should work like this = cmd.Parameters.Add("@QuoteNumber ", QuoteNumber ));
You can use something similar to this in the event handler for the click event of the button, replacing ConnectionString, quote and item with the appropriate values.
using (SqlConnection dataConn = new SqlConnection(ConnectionString))
{
dataConn.Open();
using (SqlCommand dataCommand = dataConn.CreateCommand())
{
dataCommand.CommandType = CommandType.StoredProcedure;
dataCommand.CommandText = "InsertData";
dataCommand.Parameters.AddWithValue("@QuoteNumber", quote);
dataCommand.Parameters.AddWithValue("@ItemNumber", item);
dataCommand.ExecuteNonQuery();
}
}
精彩评论