Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9160609
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T13:46:44+00:00 2026-06-17T13:46:44+00:00

I am trying to insert into two tables as one is main details of

  • 0

I am trying to insert into two tables as one is main details of customer and another table is sub details of customer. Means 1st row will take parameters from controls and 2nd table will take from datagridview. Those two has to done in one method. I tried as

public void CstmrInsUp(string cstName, string cstSName, string AdLn1, string AdLn2, string AdCity, string AdPin, string SAdLn1, string SAdLn2, string SAdCity, string SAdPin, string TelPh1, string TelPh2, string FaxNo, string MailId, string TinNo,string cstDtlName,string cstDsgntn,string cstDtMobl,string cstDtEmail)
    {
       try
        {
            int cstId=1;
            int? grntdId=0;

            cstmrDC.Connection.Open();
            trns = cstmrDC.Connection.BeginTransaction();
            cstmrDC.Transaction = trns;

            cstmrDC.customers_iu(cstId, cstName, cstSName, AdLn1, AdLn2, null, AdCity, AdPin, SAdLn1, SAdLn2, null, SAdCity, SAdPin, TelPh1, TelPh2, FaxNo, MailId, null, TinNo, 1,ref grntdId);
            cstmrDC.customerscntcts_iu(null, cstId, cstDtlName, cstDsgntn, cstDtMobl, cstDtEmail, 1);
            trns.Commit();



        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
            if (trns != null)
                trns.Rollback();
        }

    }

Here customersdtls table should fire as in datagridview rows. Iam passing parameters as

 for (int i = 0; i < dgvCustInfo.Rows.Count - 1; i++)
        {
            cstnam = dgvCustInfo.Rows[i].Cells[0].Value.ToString();
            dsgntn = dgvCustInfo.Rows[i].Cells[1].Value.ToString();
            mblNo = dgvCustInfo.Rows[i].Cells[3].Value.ToString();
            eMail = dgvCustInfo.Rows[i].Cells[4].Value.ToString();
            //cst.InsrtDgv(cstnam, dsgntn, extNo, mblNo, eMail);
            //write a log event with the user information , system information, and activity
        }

cstCls.CstmrInsUp(txtCustmr.Text, txtShrtNam.Text, txtLn1.Text, txtLn2.Text, txtCity.Text,pin.ToString(),txtSpLn1.Text,txtSpLn2.Text,txtSpCty.Text,pin.ToString(), Phn1.ToString(), Phn2.ToString(), fax.ToString(),txtEmail.Text,txtTinNo.Text,cstnam,dsgntn,mblNo,eMail);

By doing this. First one record is only saving. How can i implement to insert all rows from datagridview and controls. Thank you

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T13:46:45+00:00Added an answer on June 17, 2026 at 1:46 pm

    In your Method CstmrInsUp variable cstId is always 1. I think this is the primary key value, so it is inserting the first record with value 1. Then after that it cannot insert another row with same custid. So it is throwing an error and the transaction is rolled back.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to select data from two tables and insert it into another
I'm trying to insert data into two tables in the database, one of the
I've been trying to insert data from one row in a temporary table into
So I've been trying to insert sql into this one specific table for the
I am trying to join two tables. One being the sys.databases table and the
I have two tables. I am trying to find rows in one table which
I am trying to insert data into two different tables in the same database,
I am trying to insert into my database table using the database helper class.
I'm trying to insert multiple rows into MySql with only one INSERT INTO statement
I'am trying to insert record into db2 table and getting a result with response.write.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.