CSharp examples for System.Data.SqlClient:SqlConnection
Read data from SqlConnection
using System.Web; using System.Linq; using System.Data.SqlClient; using System.Data; using System.Collections.Generic; using System;//w w w . j a v a2s. com public class Main{ public static DataTable GettNajnowsze() { try { SqlConnection sqlConnection1 = new SqlConnection("Server=tcp:plps.database.windows.net,1433;Initial Catalog=PLPS;Persist Security Info=False;User ID=tomasoft;Password=Tomason18,;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;"); SqlCommand cmd = new SqlCommand(); SqlDataReader reader; DataTable dataTable = new DataTable(); sqlConnection1.Open(); cmd.CommandText = "Select t1,t2,t3,t4,t5,t6,t7," + "t8,t9,t10 from [dbo].[tiPSNajnowsze]"; cmd.CommandType = CommandType.Text; cmd.Connection = sqlConnection1; SqlDataAdapter da = new SqlDataAdapter(cmd); // this will query your database and return the result to your datatable da.Fill(dataTable); sqlConnection1.Close(); da.Dispose(); return dataTable; } catch (Exception ex) { AddToLog("Blad dodawania wiadomosci: " + ex.ToString()); return null; } } }