Sayfalar

Sql Connection etiketine sahip kayıtlar gösteriliyor. Tüm kayıtları göster
Sql Connection etiketine sahip kayıtlar gösteriliyor. Tüm kayıtları göster

2 Ekim 2019 Çarşamba

MSSQL Server Connection Check with .UDL


Server bağlantı ayarlarını kontrol etmek ve web config vb dosyalarda kullanmak için güzel bir yöntem

  1. Create a new blank file and name it test.udl.
  2. Double click on it, and a "Data Link Properties" dialog should appear.
  3. On "Providers" tab, select "Microsoft OLE DB Provider for SQL Server" or "SQL Native Client"
  4. On "Connections" tab, try various settings and use the "Test Connection" button to test them. Click "Ok" when it works.
  5. Open the test.udl file in Notepad and copy the line that starts with "Provider=" into your Web.config "ConnectionString" value, BUT delete the little part that says "Provider=SQLNCLI.1;"

28 Ağustos 2019 Çarşamba

ADO.NET Sql Connection ve Grid View



public List<Product> GetAll()
{
    SqlConnection con = new SqlConnection
    (@"Server=.\sqlexpress; Initial Catalog=ETrade; User Id=sa; Password=***;");
 
    if (con.State==ConnectionState.Closed)
    {
        con.Open();
    }
 
    SqlCommand sqlCommand = new SqlCommand("SELECT * FROM Products", con);        
 
    SqlDataReader sqlDataReader= sqlCommand.ExecuteReader();
 
    List<Product> products = new List<Product>();
 
    while (sqlDataReader.Read())
    {
        Product product = new Product()
        {
            Id = (Int32)sqlDataReader["Id"],
            Name = sqlDataReader["Name"].ToString(),
            UnitPrice = (decimal)sqlDataReader["UnitPrice"],
            StockAmount = (Int32)sqlDataReader["StockAmount"],
 
 
        };
 
        products.Add(product);
 
    }
 
    return products;
 
}



From Form

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }
 
    private void Form1_Load(object sender, EventArgs e)
    {
        IProductDal productDal = new ProductDal();
 
        dgwProduct.DataSource=productDal.GetAll();
 
    }
}

MVC LOADING TOO SLOW ISSUE