C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Forums » .NET » ASP.NET »

Insert record from datatable to database or gridview to database


Posted Date: 17 Jul 2008      Posted By: Tushar Jindle      Member Level: Silver     Points: 1   Responses: 3



Hi
I've some records in datatable same in gridview so can anyone tell me how to insert these records in database please tell me easy way.
should i insert records using datatable or gridview ?
I'm new in programming field
I'm using c# + sql
thanks





Responses

Author: Vijay    17 Jul 2008Member Level: SilverRating: 2 out of 52 out of 5     Points: 4

If you want to insert all the rows from the datatable then go for foreach loop. as follows..
Create SqlConnection
Create SqlCommand
foreach(DataRow dr in DataTable.Rows)
{
SqlCommand = new SqlCommand("CommandText(i.e, Insert Statement)", ConnectionObject);
SqlCommand.ExecuteNonQuery();
}

Follow this simple steps might solve your problem.



Author: vipul    17 Jul 2008Member Level: DiamondRating: 2 out of 52 out of 5     Points: 4

Hi,
for inserting record in the database you used datat able it is the best way doing this way

In c#
-----
foreach(DataRow dr in DataTable.Rows)
{
// This loop is running total of data table row
// And you get the column value this way dr["cloumnName"]
// then insert into database.
}

vipul,
http://dongavipul.blogspot.com

Please Rate This Answer If They Helpful

Thanks & Regards
Patel Vipul



Author: Tushar Jindle    17 Jul 2008Member Level: SilverRating: 2 out of 52 out of 5     Points: 3

hi
thanks for your prompt response but actually i dont know what to write here

SqlCommand cmd = new SqlCommand("CommandText(i.e, query)", con);
so please help me
I'm attaching my code file
thanks



Data Entry.aspx.cs
Post Reply

 This thread is locked for new responses. Please post your comments and questions as a separate thread.
If required, refer to the URL of this page in your new post.


Next : I want to play you tube videos in My application........
Previous : error.
Return to Discussion Forum
Post New Message
Category: ASP.NET

Related Messages



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use