Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Data.SqlClient;
- using System.Data;
- namespace ConsoleApp
- {
- class Program
- {
- static void Main(string[] args)
- {
- string conStr = @"Data Source = server1; Initial Catalog = User; Integrated Security = false; User = sa; Password = ghbvf;";
- SqlConnection sql = new SqlConnection(conStr);
- sql.Open();
- //SqlCommand cmd = new SqlCommand("create table Users(Id int identity not null, Name varchar(50) not null, Age int not null)",sql);
- //cmd.ExecuteNonQuery();
- SqlCommand cmd3 = new SqlCommand("insert Users values('Flint',30);", sql);
- cmd3.ExecuteNonQuery();
- SqlCommand cmd1 = new SqlCommand("select * from Users", sql);
- SqlDataReader dtread = cmd1.ExecuteReader();
- DataTable table = new DataTable();
- table = dtread.GetSchemaTable();
- while (dtread.Read())
- {
- table.Rows.Add(dtread.GetValue(1));
- table.Rows.Add(dtread.GetValue(0));
- }
- foreach (DataRow item in table.Rows)
- {
- for(int i=0; i<item.ItemArray.Length;i++)
- {
- Console.WriteLine(item.ItemArray[i]);
- }
- for (int i = 0; i < item.ItemArray.Length; i++)
- {
- Console.WriteLine(item.ItemArray[i]);
- }
- }
- DataTable tb = new DataTable();
- tb = dtread.GetSchemaTable();
- Console.ReadLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement