how to insert lakh of records in database at the button click one by one

Posted by Shubhashree under ASP.NET on 3/8/2009 | Views : 4958 | Status : [Member] | Replies : 3
i have a form which contains first name,lastname,email,designation in form
now i want to insert records continously may be a lakh of records
what is the exact code to be used to insert the records to the database.please help me out

thank you in advance




Responses

Posted by: Majith on: 3/8/2009 [Member] Starter

Up
0
Down
SubhaShree,

Whether you can insert thousands of records or lakhs of records the code will be same but If you are getting the values from database and you should evaluate the code to tunning and optimizing.

if you are inserting values the you would the write the query:

string s = "insert into Emp (first name,lastname,email,designation)values('" + txtFname.Text + "','" + txtLName.Text + "','" + txtEmail.Text + "','" + txtDestination.Text + "');

// For Vb.Net use & instead of + in the Query
Open the Connection and Command :

OledbConnection cn = new OledbConnection ("Provider=Microsoft.Jet.Oledb.4.0;Data Source=D:\Emp.Mdb");
cn.open();
OledbCommand cmd = new OledbCommand (s,cn);
//s the Query

cmd.ExecuteNonQuery();

cn.Close();



you can use stored procedure or BLL/DAL any layers , tiers.






Shubhashree, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Poster on: 3/9/2009 [Member] Starter

Up
0
Down
I think Mr. Sheo Narayan has written an article recently on this http://www.dotnetfunda.com/articles/article276.aspx

You can use this article as a based and write your own code. This is better way to do that as SP is much more powerful and perform well than writing sql statement directly.

Thanks

Shubhashree, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Susantaown on: 3/9/2009 [Member] Starter

Up
0
Down
Hi Shubhashree

If u know how many records u want to insert then better to user for loop like..

int count=how many records u want to insert

for(int i=0;i<count;i++)
{
string _qry="Insert into yourtable(firstname,lastname,email,designation) values(.......);
}

susant

Shubhashree, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response