Hoe to delete product
how to delete product code in Sql Data Base please tel me the Sq l Query
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Micke BlomqvistRank #1,660 · 923 reputationPosted Feb 10, 2011, 9:10 AM EST
CREATE PROCEDURE [dbo].[delete_productcode]
@ProductCode varchar(50)
AS
BEGIN
delete from product_table where productcode = @ProductCode
c.Open();
END
This assumes that the SQL Server table is named product_table and that the column holding the productcode is named productcode
Then you need to call this procedure from C# code. First add the following using statement at the top in your class:
using System.Data;
using System.Data.SqlClient;
Then call the stored prodcedure:
// Here you need to assing your productcode that you want to delete, perhaps from a textbox
string productcode = "assign the productcode to this variable";
// A connectionstring for you database
string connectionstring = "Data Source=your_machine_name;Initial Catalog=your_database;User Id=your_user;Password=your_pwd;";
using (SqlConnection c = new SqlConnection(connectionstring))
{
// Create a command with the stored procedure name and the SQL Server connection object
SqlCommand cmd = new SqlCommand("delete_productcode", c);
cmd.CommandType = CommandType.StoredProcedure;
// Assign the parameter to the stored procedure
cmd.Parameters.AddWithValue("@ProductCode", productcode);
// Execute the stored procedure
cmd.ExecuteNonQuery();
c.Close();
}
That's it!
Micke BlomqvistRank #1,660 · 923 reputationPosted Feb 15, 2011, 9:44 AM EST