Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET
Actually i am having a webform for fee-structure like below
fee-type |amount |annual/month(checkbox)
registration-fee: | textbox1| chekbox1
tution-fee: | textbox2 | checkbox2
books-fee |textbox3 |checkbox3
 
think that above is a form for fee-structure while clicking on the save button i want to save the records into below table manner
 
table fee-structure
student_id|fee_type|amount(textbox)|annual/month(checkbox)
1002 | registration-fee |1001 | 1(if checked means)
1002 | tution-fee | 2500 | 0(if not checked means)
1002 | books-fee | 2300 | 1
 
//my question is for inserting every record i have to take separate query...if not how i can write...i am giving my code below
 SqlCommand cmdInsertFeeQuotation = DBManager.DataAccess.command();
                    cmdInsertFeeQuotation.Parameters.Add(new SqlParameter("@option", SqlDbType.VarChar, 50));
                    cmdInsertFeeQuotation.Parameters["@option"].Value = "InsertFeeQuotation";
 
                    cmdInsertFeeQuotation.Parameters.Add(new SqlParameter("@Fee_Type", SqlDbType.VarChar, 50));
                    cmdInsertFeeQuotation.Parameters["@Fee_Type"].Value = "Registration Fee";
 
                    cmdInsertFeeQuotation.Parameters.Add(new SqlParameter("@Amount", SqlDbType.Money));
                    cmdInsertFeeQuotation.Parameters["@Amount"].Value = txtRegistrationFee.Text;
 
                    if (ckboxRegistrationFee.Checked == true)
                    {
                        cmdInsertFeeQuotation.Parameters.Add(new SqlParameter("@Annual_Month", SqlDbType.Bit));
                        cmdInsertFeeQuotation.Parameters["@Annual_Month"].Value = 1;
                    }
                    else
                    {
                        cmdInsertFeeQuotation.Parameters.Add(new SqlParameter("@Annual_Month", SqlDbType.Bit));
                        cmdInsertFeeQuotation.Parameters["@Annual_Month"].Value = 0;
                    }
                    
 
                    string sqlquery1 = "SchoolProc";
                    DBManager.DataAccess.executeQuery(sqlquery1);//above code is for inserting one record but i want to inser three records at a time...
Posted 25-Feb-13 22:28pm
ntitish1.5K
Edited 26-Feb-13 0:28am
v4
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

for inserting more than one record at same time you use this technique.
Add your record in a datatable and insert record with single insert statement.
http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlbulkcopy.aspx[^][]
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

you have to create array of the text box for inserting multiple record at one time save click.
  Permalink  
Comments
ntitish at 26-Feb-13 4:13am
   
sir at the same time i want to save the checkbox values and fee-type also into table ...
ntitish at 26-Feb-13 4:31am
   
how to save in array list sir...can u send me code for that if possible....
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

try using Table valued functions in SQL Server and use the following statement for ex:
 
INSERT INTO TestTable (FirstName, LastName)
SELECT FirstName, LastName
  Permalink  
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 275
1 DamithSL 265
2 CPallini 235
3 Maciej Los 185
4 George Jonsson 170
0 OriginalGriff 5,415
1 DamithSL 4,422
2 Maciej Los 3,820
3 Kornfeld Eliyahu Peter 3,470
4 Sergey Alexandrovich Kryukov 2,911


Advertise | Privacy | Mobile
Web02 | 2.8.141216.1 | Last Updated 26 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100