hoe to delete product
how to delete product code in Sql Data Base please tel me the Sq l Query
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Micke BlomqvistPosted Feb 15, 2011, 2:44 PM
Micke BlomqvistPosted Feb 10, 2011, 2:10 PM
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!