Click here to Skip to main content
15,892,927 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a table with table name= login in data base. i want show my table value in grid view.
Posted

 
Share this answer
 
Hi,

//string connection="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\aspnet.mdf;Integrated Security=True;User Instance=True;MultipleActiveResultSets=True";
string connection = "Data Source=path;Initial Catalog=commonlogin;User ID=sa;Password=; ";
 
 
SqlConnection conn = new SqlConnection(connection);
conn.Open();
SqlDataAdapter ad= new SqlDataAdapter("SELECT * FROM tbl_SqlImage", conn);
Dataset ds=new Dataset();
ad.fill(ds);
 
if(ds.tables[0].rows.count!=0)
{
          Gridview1.Datasource=ds;
          Gridview1.Databind();
}


http://www.vkinfotek.com/gridview/binding-gridview-dataset.html[^]
 
Share this answer
 
Try to bind gridview using execute reader[^] like this:
C#
try
{
        using (SqlConnection sqlConn = new SqlConnection(strConn))
        {
            using (SqlCommand sqlCmd = new SqlCommand())
            {
                sqlCmd.CommandText = "SELECT * FROM login";
                sqlCmd.Connection = sqlConn;
                sqlConn.Open();
                SqlDataReader objDataReader = sqlCmd.ExecuteReader();
                gvDetail.DataSource = objDataReader;
                gvDetail.DataBind();
                sqlConn.Close();
            }
        }
}
catch { }
 
Share this answer
 
v2
 
Share this answer
 
Comments
[no name] 16-Mar-15 3:08am    
Note that he's asking about ASP.Net, your links show information on WinForms-DGV's.

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