Click here to Skip to main content
15,899,124 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
my sql statments are as follows
the insert statement only works
update and delete statements don't work

C#
string deletecmd_PurchaseProduct =
    @"DELETE FROM PurchaseProduct Where" +
    "PurchaseProduct_No=@PurchaseProduct_No and "+
    "Purchase_InvoiceNo=@Purchase_InvoiceNo ";

string updatcmd_PurchaseProduct =
    "UPDATE PurchaseProduct "
+ "  SET    "
+ "  PurchaseProduct_SerialNo =@PurchaseProduct_SerialNo"
+ ", Purchase_InvoiceNo =@Purchase_InvoiceNo"
+ ", ProductNo =@ProductNo"
+ " PurchaseProduct_Quantity =@PurchaseProduct_Quantity "
+ ", PurchaseProduct_Unit =@PurchaseProduct_Unit"
+ ", PurchaseProduct_Price =@PurchaseProduct_Price"
+ " Where "
+ " PurchaseProduct_No=@PurchaseProduct_No";



string insertcmd_PurchaseProduct = "INSERT INTO PurchaseProduct" +
                   "(" +
                   " PurchaseProduct_SerialNo"+
                   ",Purchase_InvoiceNo" +
                   ",ProductNo" +
                   ",PurchaseProduct_Quantity " +
                   ",PurchaseProduct_Price" +
                   ",PurchaseProduct_Unit" +    //6
                   ")" +
                    "Values" +
                   "(" +
                   " @PurchaseProduct_SerialNo"+
                   ",@Purchase_InvoiceNo" +
                   ",@ProductNo " +
                   ",@PurchaseProduct_Quantity " +
                   ",@PurchaseProduct_Price" +
                   ",@PurchaseProduct_Unit" +       //6
                   ");";
Posted
Updated 25-Aug-13 23:39pm
v4
Comments
ArunRajendra 26-Aug-13 0:17am    
How are you calling this statements?
deva936 26-Aug-13 1:24am    
sa1.InsertCommand = cmdInsert_PurchaseProduct;
sa1.UpdateCommand = cmdUpdate_PurchaseProduct;
sa1.DeleteCommand = cmdDelete_PurchaseProduct;

sa1.Update(dtPurchaseProduct);
Azziet 26-Aug-13 6:03am    
what is the error ,you are getting..
ZurdoDev 26-Aug-13 13:35pm    
Just do a SQL trace and see what is happening.

1 solution

To use the update and delete query, you should use the ExecuteNonQuery; you can use the following sample code for Update:

SqlDataAdapter adapter = new SqlDataAdapter();
SqlConnection connection = new SqlConnection("Connection string here...");
string sql = "update statement here...";
try
{
connection.Open();
adapter.UpdateCommand = connection.CreateCommand();
adapter.UpdateCommand.CommandText = sql;

adapter.UpdateCommand.ExecuteNonQuery();
MessageBox.Show ("Row updated !! ");
}


you can use the following sample code for Delete:

SqlDataAdapter adapter = new SqlDataAdapter();
SqlConnection connection = new SqlConnection("Connection string here...");
string sql = "delete query here...";
try
{
connection.Open();
adapter.DeleteCommand = connection.CreateCommand();
adapter.DeleteCommand.CommandText = sql;

adapter.DeleteCommand.ExecuteNonQuery();
MessageBox.Show ("Row(s) deleted !! ");
}

I hope it will help you resolve your issue :)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900