as the Program's table has fk, I became confused.
let me show you my form;
and my coding for save is ;
sql Table defenition;
sql Stored procedure to add
ALTER PROCEDURE purchaseAdd
@voucherNo numeric(18,0),
@puchaseDate datetime,
@purchaseinvoiceNo numeric(18,0),
@vendorName nvarchar(20),
@grandTotal numeric(18,0)
AS
if not exists(select voucherNo, puchaseDate, purchaseinvoiceNo, vendorName, grandTotal from tbl_PurchaseDetail where voucherNo=@voucherNo and puchaseDate=@puchaseDate and purchaseinvoiceNo=@purchaseinvoiceNo and vendorName=@vendorName and grandTotal=@grandTotal)
begin
INSERT INTO tbl_PurchaseDetails
(voucherNo, puchaseDate, purchaseinvoiceNo, vendorName, grandTotal)
VALUES (@voucherNo,@puchaseDate,@purchaseinvoiceNo,@vendorName,@grandTotal)
end
here is the Sp class of purchase
public void purchaseAdd(purchaseInfo InfoPurchase)
{
try
{
if (sqlCon.State == ConnectionState.Closed)
{
sqlCon.Open();
}
SqlCommand c = new SqlCommand("purchaseAdd", sqlCon);
c.CommandType = CommandType.StoredProcedure;
c.Parameters.Add("@voucherNo", SqlDbType.Decimal).Value = InfoPurchase.voucherNo;
c.Parameters.Add("@puchaseDate", SqlDbType.DateTime).Value = InfoPurchase.puchaseDate;
c.Parameters.Add("@purchaseinvoiceNo", SqlDbType.Decimal).Value = InfoPurchase.purchaseinvoiceNo;
c.Parameters.Add("@vendorName", SqlDbType.NVarChar).Value = InfoPurchase.vendorName;
c.Parameters.Add("@grandTotal", SqlDbType.Decimal).Value = InfoPurchase.grandTotal;
int inCount = c.ExecuteNonQuery();
if (inCount > 0)
{
MessageBox.Show("Saved Successfully");
}
}
catch (Exception ex)
{
MessageBox.Show("purSP01" + ex.Message);
}
finally
{
sqlCon.Close();
}
}
and finally the code in btnSave_click event
int purchaseRate=0;
int Quantity=0;
int Discount=0;
int grandTotal = purchaseRate * Quantity - Discount;
purchaseInfo infoPurchase = new purchaseInfo();
purchaseSP SpPurchase = new purchaseSP();
infoPurchase.voucherNo = decimal.Parse(txtvoucherNo.Text);
infoPurchase.vendorName = txtvenderName.Text;
infoPurchase.purchaseinvoiceNo = decimal.Parse(txtpurchaseInvNo.Text);
infoPurchase.puchaseDate = DateTime.Parse(dtpPurchaseDate.Text);
infoPurchase.grandTotal = decimal.Parse(dgvPurchaseDetails.CurrentRow.Cells[5].ToString());
SpPurchase.purchaseAdd(infoPurchase);
My task is:-
1) enter voucherNo,InvoiceNo,purchase Date and vender Name
2) then if I click on Add Product btn, want to go to the form frmAddProduct and when i select one of the row in gridview, the itemname(in combox column of purchase details) and purchase rate( in the purchase rate column of gridview in purchaseDetails form) to be displyed.
3) then enter Quantity, discount and the grand Total will be increment automatically.
4) then save these data by clicking in btnsave.

Bineesh ViswanathPosted Jul 22, 2013, 4:35 AM
I cannot upload this in this site.
if you don't mind, give your email id and I will send my project to that email.
reply whatever in your mind
Iftikar HussainPosted Jul 22, 2013, 3:51 AM
Regards,
Iftikar
Bineesh ViswanathPosted Jul 22, 2013, 3:50 AM
all in correct way.
I have a request;
My project have only 3 forms, and a database.
shall i upload in this in order to get repair from your side?
I think this is the best method to my questions and your reply.
you can run my project by connecting to database.
Then the error can be easily found.
I only upload after you agree with me.
so reply
Iftikar HussainPosted Jul 22, 2013, 3:31 AM
Regards,
Iftikar
Bineesh ViswanathPosted Jul 22, 2013, 3:24 AM
I checked whether i decalred DateTime as string and found that nothing error in my data type declaration.
Why I getting this message?
Bineesh ViswanathPosted Jul 22, 2013, 2:32 AM
So please give the solution to the following.
How can check datagridView's value is null or not?
give me step by step procedure.
Iftikar HussainPosted Jul 22, 2013, 2:15 AM
Regards,
Iftikar
Bineesh ViswanathPosted Jul 22, 2013, 2:11 AM
I am getting a error in it.here is the error;
Iftikar HussainPosted Jul 22, 2013, 1:53 AM
Are you able to save purchase details?
Regards,
Iftikar