TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
sathish kumar
NA
117
165.2k
How to check a column value in a table and update that value
Aug 1 2012 12:42 AM
Hi friends..
I have to check a column value in a table , and i want to update that value. My coding and table structure is below. It shows syntax error at where condition in else statement.
also...while checking with break point it enters into else condition and shows syntax error near Where.
string strSQL3 = "SELECT PurchaseRtn_Qty FROM [Stock] where [ItemName]='" + txtDescription.Text + "' and [BatchNo]='" + txtBatchNo.Text + "'";
SqlCommand cmdStockQty = new SqlCommand(strSQL3, sqlConn);
object Qty = cmdStockQty.ExecuteScalar();
if (Qty == DBNull.Value)
{
string strSQL2 = "Update [Stock] set [PurchaseRtn_Qty]=" +txtQty.Text+ " where [ItemName]='" + txtDescription.Text + "' and [BatchNo]='" + txtBatchNo.Text + "'";
SqlCommand cmdStock = new SqlCommand(strSQL2, sqlConn);
cmdStock.ExecuteNonQuery();
}
else
{
string strSQL2 = "Update [Stock] set [PurchaseRtn_Qty]=[PurchaseRtn_Qty]+ "+txtQty.Text+" where [ItemName]='" + txtDescription.Text + "' AND [BatchNo]='" + txtBatchNo.Text + "'";
SqlCommand cmdStock = new SqlCommand(strSQL2, sqlConn);
cmdStock.ExecuteNonQuery();
}
i checked like below also:
string strSQL2 = "Update [Stock] set [PurchaseRtn_Qty]=(PurchaseRtn_Qty)+ '" + (Convert.ToInt32(txtQty.Text)) + "' where [ItemName]='" + txtDescription.Text + "' and [BatchNo]='" + txtBatchNo.Text + "'";
its firing but t value is not updated from null. Anyone help me please....Its urgent....
CREATE TABLE [dbo].[Stock](
[ItemCode] [nvarchar](50) NULL,
[ItemName] [nvarchar](100) NULL,
[BatchNo] [nvarchar](50) NULL,
[ExpiryDate] [datetime] NULL,
[SalesRate] [float] NULL,
[MRP] [float] NULL,
[PurchaseRate] [float] NULL,
[Opening_Qty] [int] NULL,
[Closing_Qty] [int] NULL,
[Purchase_Qty] [int] NULL,
[Sales_Qty] [int] NULL,
[PurchaseRtn_Qty] [int] NULL,
[SalesRtn_Qty] [int] NULL,
[Issue_Qty] [int] NULL,
[Return_Qty] [int] NULL,
[Opening_Value] [float] NULL,
[Purchase_Value] [float] NULL,
[Closing_Value] [float] NULL,
[Sales_Value] [float] NULL,
[SalesRtn_Value] [float] NULL,
[PurchaseRtn_Value] [float] NULL,
[VatPer] [float] NULL
) ON [PRIMARY]
Reply
Answers (
2
)
Property Of Dataset in ADO.NET
Use Of Dataset Properties in ADO.NET