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
Carol Cashman
NA
74
11.7k
Error when trying reduce a certain number from the database
Jan 8 2018 9:11 AM
hey guys,
I am creating a Materials resource planning system for an admin to be able to keep track of the materials needed, used etc.
When I receive an order via the phone the admin will enter in the size of the product they want and the amount of boxes needed (20 items per box).
This will then calculate all the materials needed to make the order (eg: small Jars, Large Jars, lids and stickers).
I am looking to find a solution to when the order is put through the system to deduct these materials needed to complete this order, to make sure the stock levels are kept up to date and do not run out of materials.
Therefore i am looking for a way to take the figure that shows up in a label on a web form away from the database level which is stored in a table called StockTable.
I have this code only for one material (stickers) to see if it worked, which it didnt.
this is my code:
protected
void
Button1_Click(
object
sender, EventArgs e)
{
//Creating a connection to my database using the connection string
string
cs = System.Configuration.ConfigurationManager.ConnectionStrings[
"RegistrationConnectionString"
].ConnectionString;
SqlConnection con =
new
SqlConnection(cs);
//preparing a query which will delete a row in the database based on the id that is entered
SqlCommand cmd =
new
SqlCommand(
"UPDATE StockTable SET AmtOfStickers-'"
+ txtStickers.Text, con);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
Response.Redirect(
"stock.aspx"
);
}
}
this is the error i am getting:
An exception of type 'System.InvalidOperationException' occurred in System.Data.dll but was not handled in user code
Additional information: ExecuteNonQuery: Connection property has not been initialized.
any advice is greatly appriciated.
Reply
Answers (
4
)
Receive sms message through Modem
how to notify when stock levels have reached below a certain