c# - ADO.NET example that has no logic, dataGrid fill from uknown data -


ok guys, here code have logic , it's simple, result brings datagrid has no logic @ all.

here sql query making table , fill table

 create table students (     id int primary key identity,     firstname nvarchar(50),     lastname nvarchar(50),     gender nvarchar(50) ) go   insert students values ('mark', 'hastings', 'male') insert students values ('steve', 'pound', 'male') insert students values ('ben', 'hoskins', 'male') insert students values ('philip', 'hastings', 'male') insert students values ('mary', 'lambeth', 'female') go 

here code behind, simple u see

string  cs=configurationmanager.connectionstrings["sampleconnectionstring"].connectionstring;         sqlconnection con = new sqlconnection(cs);          sqlcommand cmd = new sqlcommand ("select * students", con);       con.open();          sqldatareader rdr = cmd.executereader();         while (rdr.read())       {     gridview1.datasource = rdr;             gridview1.databind();         }  con.close(); 

and aspx

<div>    <asp:gridview id="gridview1" runat="server"></asp:gridview> </div> 

the result in datagrid ;

studentid   studentname 2           john 

if u see, there no john in table , can't figure out it's going.....

this made in vs2013 , framework 4.5 , mssql 2014

thx

before create table students, insert :

 drop table if exist students 

Comments

Popular posts from this blog

php - Zend Framework / Skeleton-Application / Composer install issue -

c# - Better 64-bit byte array hash -

python - PyCharm Type error Message -