How to bind a new sqlcommand in Gridview in C# expression edition


hi,

i am  using c# expression 2010. app.config file follows. beginner in c#. app.config file follows

<?xml version="1.0" encoding="utf-8" ?>  <configuration>    <configsections>    </configsections>    <connectionstrings>      <add name="windowsformsapplication1.properties.settings.employeeconnectionstring"        connectionstring="provider=microsoft.jet.oledb.4.0;data source=|datadirectory|\employee.mdb;jet oledb:database password=getorg"        providername="system.data.oledb" />    </connectionstrings>  </configuration>

 

how can databind grid view control  using sql "select birthdat , empname  employee" in form_load event.

with thanks

polachan

 

 


polachan

add reference "system.configuration"

using following code

  using system; using system.configuration; using system.data.sqlclient; using system.windows.forms;  private void form1_load(object sender, eventargs e)     {       string connectionstring = configurationmanager.connectionstrings["windowsformsapplication1.properties.settings.employeeconnectionstring"].connectionstring;       using (sqlconnection conn = new sqlconnection(connectionstring))       {         conn.open();         using (sqlcommand cmd = new sqlcommand("select birthdat , empname employee", conn))         {           sqldatareader reader = cmd.executereader();           datagridview1.datasource = reader;                   }       }     }  

 


thanks,
a.m.a.l hashim
microsoft valuable professional
dot net goodies
don't hate hacker, hate code


Visual Studio Languages  ,  .NET Framework  >  Visual C#



Comments

Popular posts from this blog

Azure DocumentDB Owner resource does not exist

job syspolicy_purge_history job fail in sqlserver 2008

Trying to register with public marketplace error with 'Get-AzureStackStampInformation'