Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i have created a table in sql server ..!!!
now i am trying to display the data on website by click a button !!

so that i written a code behind in button_click to view the table in website ...!!!

protected void Button1_Click(object sender, EventArgs e)
   {

     string connStr = ConfigurationManager.ConnectionStrings["conn"].ToString();
     SqlConnection conn = new SqlConnection(connStr);
     conn.Open();
     string query = "SELECT * FROM [Employee]  ";
     SqlCommand dCmd = new SqlCommand(query, conn);
     conn.Close();


   }


still i have to upgrade my code ...
can any one plz help me on diz
Posted
Updated 8-Nov-10 0:13am
v2
Comments
Baji Jabbar 8-Nov-10 6:14am    
not clear

Take a grid view on your page and assign datasource as your datatable..,

There are Thousands of examples are available in Google.., Try Your Self..
 
Share this answer
 
Comments
Baji Jabbar 8-Nov-10 6:47am    
good one :)
hey pubby,

you can do something like this-

public DataTable GetDataTable(string query)
        {
            SqlConnection conn = new SqlConnection(ConfigurationSettings.AppSettings["conn"].ToString());
            SqlDataAdapter adapter = new SqlDataAdapter();
            adapter.SelectCommand = new SqlCommand(query, conn);
            DataTable FilteredDataTable = new DataTable();
            conn.Open();
            try
            {
                adapter.Fill(GetDataTable);
            }
            finally
            {
                conn.Close();
            }
            return GetDataTable;
        }

RadGrid1.DataSource = GetDataTable("SELECT UID, Email_TemplateName as 'Name', Mail_Text as 'Mail text',Mail_Subject as 'Mail Subject' FROM Entry");

in web config--
<pre lang="xml"><appSettings>
    <add key="conn" value="Data Source=Amit;Initial Catalog=Entry;User ID=sa;Password=as" />
  </appSettings>




which control are you using to view the db table value?..its for radgrid control.Set it as data source for ur control and your done !!

Amit
 
Share this answer
 
v2
If you want to get the data from the table use dataset or datareader :)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900