Monday, 24 February 2014

how to connect database in c# code project

Connecting the data to database and fetch the records from database and fill the Data adopter; and assign that value to Datatable;


protected void btnShow_Click(object sender, EventArgs e)
        {
            BindData();
        }
        private void BindData()
        {
            try
            {
                string _connectionstring = @"Data Source=.\SQLEXPRESS;Initial Catalog=Northwind;Integrated Security=True";
                string _sql = "SELECT * FROM [Orders]";
                SqlConnection _connection = new SqlConnection(_connectionstring);
                SqlCommand _command = new SqlCommand(_sql, _connection);
                SqlDataAdapter _adapter = new SqlDataAdapter(_command);
                DataTable _table = new DataTable();
                _adapter.Fill(_table);
              
            }
            catch
            {
                throw;
            }

        }

No comments:

Post a Comment

Others

You will like to read it