Click here to Skip to main content
15,936,565 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
i have textbox and let i give a value 20 and when i click the button how it will generate 20 number of rows in my database table(e.g. tbl_employee)..please help me.....
Posted
Updated 18-Aug-12 0:00am
v2
Comments
Sangramsingh Pawar 18-Aug-12 5:30am    
Execute insert query 20 times
AmitGajjar 18-Aug-12 6:01am    
what about 20 employee information ? from where you will fetch those employee information ?
Sangramsingh Pawar 18-Aug-12 6:08am    
here I just gave him a hint for how to generate 20 columns, I can not post all code in comment
AmitGajjar 18-Aug-12 6:12am    
it's by mistake reply to you. actually it's for OP.

1 solution

I dont know what you are implying but here is my logic
you could use for loop
C#
for(int i=0; i<20; i++)
{
    string sqlQuery = "INSERT INTO table(blah)";
    sqlQuery += "VALUES (@blah)";
    using (SqlConnection dataConnection = new SqlConnection(connectionString))
    {
        using (SqlCommand dataCommand = dataConnection.CreateCommand())
            {
            dataConnection.Open();
            dataCommand.CommandType = CommandType.Text;
            dataCommand.CommandText = sqlQuery;
            dataCommand.Parameters.Add("@blah", text to insert);
            dataCommand.ExecuteNonQuery();
            dataConnection.Close();
            }
    }
}
 
Share this answer
 
Comments
Manash Sahoo 18-Aug-12 5:56am    
thanks a lot it works......

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900