TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
SUNIL GUTTA
NA
1k
393.9k
data copying b/w 2 tables ?
Dec 23 2013 1:30 AM
Hi buddies
well say i have table with data .. i want to copy the same data to other table ..
PS : Here copy() should not be used .. Well i know there is a way to achieve this i.e using clone and later Rows.add() ..
But I NEED IS , CAN ANYONE correct the stupid code i written i.e data copying b/w tables via datasetsusing forLoop ?/
My code so far :
private void Form1_Load(object sender, EventArgs e)
{
con = new SqlConnection("Data Source=sunil-pc;Initial Catalog=formdb;User ID=sa;Password=123");
SqlCommand cmd = new SqlCommand("select * from formtable", con);
da = new SqlDataAdapter(cmd);
ds = new DataSet();
da.Fill(ds, "table1");
dataGridView1.DataSource = ds.Tables[0];
}
private void button1_Click(object sender, EventArgs e)
{
DataSet ds1 = new DataSet();
int columns = ds.Tables[0].Columns.Count;
int rows = ds.Tables[0].Rows.Count;
for (int i = 0; i < rows; i++)
{
for (int j = 1; j < columns + 1; j++)
{
ds1.Tables[0].Rows[i][j] = ds.Tables[0].Rows[i][j];
}
}
dataGridView2.DataSource = ds1.Tables[0];
}
Well i hope i am clear :) Ty for help
Have a nice day :)
Reply
Answers (
4
)
How to display current temperature ll shown on my aspx page
showing data from database