Search This Blog
2010/01/17
Populating Dataset with 2 tables in C#:
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
namespace Adapter_Dataset
{
class Program
{
static void Main(string[] args)
{
SqlConnection con = new SqlConnection("Integrated security=SSPI;Initial Catalog=sangram;Data source=(local)");
con.Open();
SqlDataAdapter da = new SqlDataAdapter("select * from course", con);
DataSet ds = new DataSet();
da.Fill(ds,"course");
da = new SqlDataAdapter("select * from student", con);
da.Fill(ds, "student");
Console.WriteLine("Course Table");
foreach (DataRow drow in ds.Tables["course"].Rows)
{
Console.Write("Cno:"+ drow[0].ToString());
Console.Write(" Cname:"+ drow[1]);
Console.Write(" Duration:"+ drow[2].ToString());
Console.Write(" Fees:"+drow[3].ToString());
Console.WriteLine();
}
Console.WriteLine("Student Table");
foreach (DataRow drow in ds.Tables["student"].Rows)
{
Console.Write("Sno:"+drow[0].ToString());
Console.Write(" Sname:"+ drow[1]);
Console.Write(" Cno:"+ drow[2].ToString());
Console.WriteLine();
}
Console.ReadKey();
}
}
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment