apirnia
asked on
C# Get data from SQL Server and display it
I want to know How I can make an aspx page with one button "Click Me" and as soon as user clicks on it, I will get data from my database and displays in on the browser in a table and all in C#.
I already have dome tons of readings but I cant put all the parts together.
So far I have added this to my web.config:
<appSettings>
<add key="dbconnection" value="server=local;databa se=MyTesti ng;uid=tes tx;passwor d=testy;" />
</appSettings>
On my codebehind I have the following namespaces:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls ;
using System.Configuration; //For Web Config
using System.Data.SqlClient; //Do I need this one??????
and my Query is:
sSQL = "Select * from Client" ;
I already have dome tons of readings but I cant put all the parts together.
So far I have added this to my web.config:
<appSettings>
<add key="dbconnection" value="server=local;databa
</appSettings>
On my codebehind I have the following namespaces:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls
using System.Configuration; //For Web Config
using System.Data.SqlClient; //Do I need this one??????
and my Query is:
sSQL = "Select * from Client" ;
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
apirinia,
CommandBehavior.CloseConne ction is optional . This tells the reader to close the Connection object when the DataReader object is closed. If you do not use, you should close Database connection after you close the DataReader. Just an extra feature to avoid a pitfall. remember open databae connections are some of most the common mistakes in web applications
CommandBehavior.CloseConne
ASKER
dgEmployees.DataSource = myCommand.ExecuteReader(Co
In your example you did it like this:
dgEmployees.DataSource = myCommand.ExecuteReader();
What is this part exactly do? "CommandBehavior.CloseConn
If I do that whould I still need "myConnection.Close();" ??
Thanks