Notes
Notes - notes.io |
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Runtime.Intrinsics.Arm;
using System.Text;
using System.Threading.Tasks;
namespace Proj
{
internal class DataAdapter
{
SqlConnection conn;
SqlConnection conn1;
string connectionString = "Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=Northwind;Integrated Security=SSPI";
string connectionString1 = "Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=Practice6;Integrated Security=SSPI";
public DataAdapter()
{
conn = new SqlConnection(connectionString);
conn1 = new SqlConnection(connectionString1);
}
static void Main()
{
DataAdapter d = new DataAdapter();
// d.ReaddataInNorthwind();
// d.ReadDataInPracticeDB();
d.ReaddataTopFive();
}
public void ReaddataTopFive()
{
SqlDataReader rdr = null;
try
{
conn.Open();
//SqlCommand cmd = new SqlCommand("Select top 5 * from Customers", conn);
SqlDataAdapter d = new SqlDataAdapter("Select top 5 * from Products ORDER BY UnitPrice", conn);
DataSet ds = new DataSet();
d.Fill(ds, "data");
var table = new ConsoleTable("Name");
foreach (DataRow row in ds.Tables["data"].Rows)
{
table.AddRow(row["ProductName"]);
//Console.WriteLine(row["ProductName"]);
}
Console.WriteLine(table);
/* while (rdr.Read())
{
Console.WriteLine(rdr[1] + "tttt" + rdr[2]);
}*/
}
finally
{
if (rdr != null)
{
rdr.Close();
}
if (conn != null)
{
conn.Close();
}
}
}
public void ReaddataInNorthwind()
{
SqlDataReader rdr = null;
try
{
conn.Open();
//SqlCommand cmd = new SqlCommand("Select top 5 * from Customers", conn);
SqlDataAdapter d = new SqlDataAdapter("Select top 5 * from Employees", conn);
SqlDataAdapter d1 = new SqlDataAdapter("Select top 5 * from Orders", conn);
DataSet ds = new DataSet();
d.Fill(ds, "data");
d1.Fill(ds, "data1");
// DataRelation dr = new DataRelation("combined", ds.Tables["data"].Columns["EmployeeID"], ds.Tables["data1"].Columns["EmployeeID"]);
//ds.Relations.Add(dr);
foreach (DataRow row in ds.Tables["data"].Rows)
{
Console.WriteLine(row["ContactName"]);
}
Console.WriteLine();
foreach (DataRow row in ds.Tables["data1"].Rows)
Console.WriteLine(row["ProductName"]);
/* while (rdr.Read())
{
Console.WriteLine(rdr[1] + "tttt" + rdr[2]);
}*/
}
finally
{
if (rdr != null)
{
rdr.Close();
}
if (conn != null)
{
conn.Close();
}
}
}
public void ReadDataInPracticeDB()
{
SqlDataReader rdr = null;
try
{
conn.Open();
//SqlCommand cmd = new SqlCommand("Select top 5 * from Customers", conn);
SqlDataAdapter d = new SqlDataAdapter("Select * from Orders", conn1);
SqlDataAdapter d1 = new SqlDataAdapter("Select * from Product", conn1);
DataSet ds = new DataSet();
d.Fill(ds, "data");
d1.Fill(ds, "data1");
// DataRelation dr = ds.Relations.Add("combined data", ds.Tables["data"].Columns["CustomerID"], ds.Tables["data1"].Columns["CustomerID"]);
foreach (DataRow row in ds.Tables["data"].Rows)
{
Console.WriteLine(row["CustomerID"]);
}
Console.WriteLine();
foreach (DataRow row in ds.Tables["data1"].Rows)
Console.WriteLine(row["name"]);
/* while (rdr.Read())
{
Console.WriteLine(rdr[1] + "tttt" + rdr[2]);
}*/
}
finally
{
if (rdr != null)
{
rdr.Close();
}
if (conn != null)
{
conn.Close();
}
}
}
}
}
|
Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...
With notes.io;
- * You can take a note from anywhere and any device with internet connection.
- * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
- * You can quickly share your contents without website, blog and e-mail.
- * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
- * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.
Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.
Easy: Notes.io doesn’t require installation. Just write and share note!
Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )
Free: Notes.io works for 12 years and has been free since the day it was started.
You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;
Email: [email protected]
Twitter: http://twitter.com/notesio
Instagram: http://instagram.com/notes.io
Facebook: http://facebook.com/notesio
Regards;
Notes.io Team