我正在使用库存软件来购买产品。我希望在购买和销售后获得利润损失。购买表格工作正常。现在我想从销售形式销售产品,并希望获得购买发票编号,其中手数量大于0,并且针对每个datagridview行项目名称获利。所以请告诉我如何在insert命令中定义子查询,从购买表中获取Pur_Invoice_No。 在下面给出的查询是生成双值错误。
购买表
Sale_Invoice_No Item_Code Item_Batch_No Item_Pur_InvoiceNo Item_Sale_Quantity Item_Unit_RetailPrice Sale_Item_Discount Item_Discount_Amount
1 1 1 5 1 5 1 2
try
{
SqlConnection conn = new SqlConnection("Data Source=.;Initial Catalog=mateenwin;User ID=sa;Password=123");
conn.Open();
SqlCommand commandd = new SqlCommand("Select max(Sale_Invoice_No) from Sale", conn);
if (string.IsNullOrEmpty(commandd.ExecuteScalar().ToString()))
{
InvoiceNo = Convert.ToInt32(1);
}
else
{
int tig =Convert.ToInt32( 1);
InvoiceNo = Convert.ToInt32(commandd.ExecuteScalar()) +tig;
}
foreach (DataGridViewRow row in saved.dataGridView1.Rows)
{
if (row.IsNewRow) continue;
int batch = 1;
for(int i=0;i>batch;i++)
{
}
SqlConnection cons = new SqlConnection("Data Source=.;Initial Catalog=mateenwin;User ID=sa;Password=123");
SqlCommand command = new SqlCommand("Insert into Sale (Sale_Invoice_No,Payment_Type_ID,Customer_ID,Sale_Reference,Sale_Remarks,Item_Code,Item_Sale_Quantity,Item_Unit_RetailPrice,Sale_Item_Discount,Item_Discount_Amount,Item_Payable_Amount,Cash_Received,Return_Amount,Login_ID,User_ID,Item_Pur_InvoiceNo,Sale_Entry_Date)Values ('" + InvoiceNo + "','" + saved.comboBox1.SelectedValue + "','" + saved.comboBox2.SelectedValue + "','" + saved.textBox3.Text + "','" + saved.textBox4.Text + "','" + row.Cells[6].EditedFormattedValue + "','" + row.Cells[1].EditedFormattedValue + "','" + row.Cells[2].EditedFormattedValue + "','" + row.Cells[3].EditedFormattedValue + "','" + row.Cells[4].EditedFormattedValue + "','" + row.Cells[5].EditedFormattedValue + "','" + saved.textBox10.Text + "','" + saved.textBox11.Text + "','" + saved.comboBox3.SelectedValue + "','" + this.comboBox2.SelectedValue + "',(Select DISTINCT Pur_Invoice_No IN (Select DISTINCT Pur_Invoice_No from Purchase where Purchase.Item_Code ='" + row.Cells[6].EditedFormattedValue + "')), GetDate())", cons);
cons.Open();
using (cons)
{
command.ExecuteNonQuery();
}
}
MessageBox.Show("Invoice successfully Saved");