I have a SQL command I am running that works great however for one of the AddWithValue parameters I want to use another SQL command to get that value... this is what I have but the cmd2 I want to use isn't working. Is it even possible to get data that way in theory it makes sense but it doesn't seem to work..
cmd2 = new SqlCommand("SELECT acctNum FROM custInfo WHERE customerName = @customerName", cn);
cmd2.Parameters.AddWithValue("@customerName", customerDropDown.Text);
cmd = new SqlCommand("UPDATE custInfo SET ctGal = (ctGal - (@contractGallons)) WHERE acctNum = @acctNum", cn);
cmd.Parameters.AddWithValue("@contractGallons", gallonsTextBox.Text)
cmd.Parameters.AddWithValue("@acctNum", cmd2);
update ... where acctNum in (select c.acctNum from custInfo c ...)?cmd2to get theacctNumvalue. But @DmitryBychenko will work better since it's only 1 call to the db.UPDATE custInfo SET ctGal = (ctGal - (@contractGallons)) WHERE customerName = @customerName- You don't actually need theacctNumif you already have the@customerName...