프로그램에서 데이터베이스로의 데이터는 어떻게 뺍니까?프로그램에서 데이터베이스로의 마이너스 데이터
내 데이터베이스에 수량 및 설명이 있습니다. 수량은 100이 될 것이고, 그 설명은 A. 것이다
전 (후 프로그램을 실행하는) 이런 내 프로그램에 입력 양은 50이고 그것의 설명은 A.
인데이터베이스 : 수량이 될 것입니다 50 (데이터베이스 내 프로그램을 빼기 때문에 "100-50 = 50", 여전히 설명 A와 동일하게 유지
내가 어떻게해야합니까
인가?미리 감사드립니다.
편집 :
나는 이미이 좋아했다 : 내가 프로그램을 실행할 때, 양이 데이터베이스처럼 정확히 같은로드
if (textBoxCodeContainer[index].TextLength != 0)
{
this.textBoxQuantityContainer[index].Value = Convert.ToDecimal(dReader["Quantity"].ToString());
this.textBoxDescContainer[index].Text = dReader["Description"].ToString();
this.textBoxSubTotalContainer[index].Text = dReader["Price"].ToString();
}
if (textBoxQuantityContainer[index].Value != 0)
{
if (textBoxQuantityContainer[index].Value >= Convert.ToDecimal(dReader["Quantity"].ToString()))
{
decimal newVal = textBoxQuantityContainer[index].Value - Convert.ToDecimal(dReader["Quantity"].ToString());
cmd = new OleDbCommand("UPDATE [Seranne] SET [Quantity] ='" + newVal + "' WHERE [Code] IN (");
}
}
을하지만, 내가 입력 할 때 그것은 변경할 수 없습니다 수량이 50이면 프로그램이 자동으로 100으로 돌아갑니다 (데이터베이스의 수량과 정확히 같습니다)
왜 그런가요?
참고 : 텍스트 상자 수량의 경우 숫자를 위로 사용합니다.
편집 : 전체 코드는 아래에있다 : "또한 이
"코드 "가 위의 데이터베이스를 참조하는 스크린 샷에 표시하고, 다음은
private void UpdateDatas()
{
int codeValue = 0;
int index = 0;
if (firstForm.textBox1.Text == "Seranne")
{
string query = "SELECT [Quantity], [Description], [Price] FROM [Seranne] WHERE [Code] IN (";
OleDbDataReader dReader;
OleDbConnection conn = new OleDbConnection(connectionString);
conn.Open();
if (int.TryParse(this.textBoxCodeContainer[0].Text, out codeValue))
{
query = query + codeValue.ToString();
}
for (int i = 1; i < 17; i++)
{
if (int.TryParse(this.textBoxCodeContainer[i].Text, out codeValue))
{
query = query + "," + codeValue.ToString();
}
}
query = query + ")";
OleDbCommand cmd = new OleDbCommand(query, conn);
cmd.Parameters.Add("Code", System.Data.OleDb.OleDbType.Integer);
cmd.Parameters.Add("Quantity", System.Data.OleDb.OleDbType.Integer);
dReader = cmd.ExecuteReader();
while (dReader.Read())
{
if (textBoxCodeContainer[index].TextLength != 0)
{
this.textBoxQuantityContainer[index].Value = Convert.ToDecimal(dReader["Quantity"].ToString());
this.textBoxDescContainer[index].Text = dReader["Description"].ToString();
this.textBoxSubTotalContainer[index].Text = dReader["Price"].ToString();
}
if (textBoxQuantityContainer[index].Value != 0)
{
if (textBoxQuantityContainer[index].Value >= Convert.ToDecimal(dReader["Quantity"].ToString()))
{
decimal newVal = textBoxQuantityContainer[index].Value - Convert.ToDecimal(dReader["Quantity"].ToString());
cmd = new OleDbCommand("UPDATE [Seranne] SET [Quantity] ='" + newVal + "' WHERE [Code] IN (");
}
}
index += 1;
}
dReader.Close();
conn.Close();
}
}
private void UpdatePrice()
{
int totalPrice = 0;
int quantity = 0;
int price = 0;
for (int i = 0; i < 17; i++)
{
if (textBoxQuantityContainer[i].Value > 0)
{
quantity = (int)textBoxQuantityContainer[i].Value;
price = Convert.ToInt32(textBoxSubTotalContainer[i].Text);
textBoxTotalContainer[i].Text = (quantity * price).ToString();
}
else
{
textBoxSubTotalContainer[i].Text = "";
textBoxTotalContainer[i].Text = "";
}
}
for (int i = 0; i < 17; i++)
{
if (textBoxTotalContainer[i].TextLength != 0)
{
totalPrice += Convert.ToInt32(textBoxTotalContainer[i].Text);
}
}
textBoxAllTotalContainer.Text = totalPrice.ToString("n2");
}
private void textBox_TextChanged(object sender, EventArgs e)
{
UpdateDatas();
UpdatePrice();
}
}
}
이 스크린 샷입니다 Quantity ", 이미 데이터베이스에있는 코드를 입력 할 때마다 나머지 상자가 채워집니다. 그러나 "수량"을 100에서 50으로 변경하면 자동으로 프로그램을 새로 고침하여 100으로 다시 되돌릴 수 있습니다. 이 닫는 따옴표와 브래킷을 찾을 수 없기 때문에
어머, 전체 코드를 게시 할 필요가 없습니다.확실히 관련성이있는 메소드로만 줄일 수 있습니다. –
Andy G : 댓글에서 질문하는 "코드"가 데이터베이스를 참조합니다. 기본적으로 "코드"는 스크린 샷의 나머지 상자 ("수량", "Desc", "소계", "합계")에 텍스트를 표시하기 위해 채워야하는 필수 요소입니다. – Reinhardt