.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Forum >> C# >> Post New QuestionBookmark and Share Subscribe to Forum

hai can any one provide me a small c# program with sql connection

Posted By: siri.k     Posted Date: June 21, 2011    Points:5   Category :C#
a small programm on grid view with sql connection in detail plz

Responses
Author: Gowthammanju             
Posted Date: June 21, 2011     Points: 20   

try these link u will find a way


http://www.dotnetspark.com/kb/Content.aspx?id=4204

Thanks & Regards,
GowthamManju
Chennai



Mark if the answer is true
Author: siri.k             
Posted Date: June 21, 2011     Points: 20   

hi i saw the link u provided but lz give me grid view exple with connection simple grid we example in detail

Author: Vilas Gite             
Posted Date: June 21, 2011     Points: 20   

hi please check this,
http://www.c-sharpcorner.com/UploadFile/73ba73/7161/?ArticleID=63b40f15-b9a8-4e27-a4f1-0625b4be4c55

---------------
If Its helps you. "MARK AS ANSWER!"


Author: Vilas Gite             
Posted Date: June 21, 2011     Points: 20   

ok Siri please open attached file..


Download Attachment

Author: Gowthammanju             
Posted Date: June 21, 2011     Points: 20   

Hey Vilas Gite


just replace the coding as


string con = "Data Source=dbServer;Initial Catalog=testDB;Integrated Security=True";

SqlConnection sqlConnection = new SqlConnection(con);

SqlCommand sqlCommand = new SqlCommand("select * from table1", sqlConnection);

sqlConnection.Open();



SqlDataReader reader = sqlCommand.ExecuteReader();



GridView1.DataSource = reader;

GridView1.DataBind();



thats it.....

Thanks & Regards,
GowthamManju
Chennai



Mark if the answer is true
Author: Sasi Prabhu             
Posted Date: June 22, 2011     Points: 20   

Bind Values into gridview using DataSet:

In web.config File:

<connectionStrings>
<add name="DBConnection" connectionString="Data Source=.;Initial Catalog=DataBaseNa,e;User ID=UrUserName;Password=UrPassword" providerName="System.Data.SqlClient"/>
</connectionStrings>


In aspx.cs :

System.Data.SqlClient.SqlConnection con=new System.Data.SqlClient.SqlConnection(System.Configuration.ConfigurationManager.connectionStrings[""].ConnectionString);
System.Data.SqlClient.SqlCommand cmd;
System.Data.DataSet ds=new System.Data.DataSet();
System.Data.SqlClient.SqlDataAdapter da;



con.open();
cmd=new System.Data.SqlClient.SqlCommand("Select * from TableName",con);
da=new System.Data.SqlClient.SqlDataAdapter(cmd);
da.Fill(ds);
GridView1.DataSource=ds;
GridView1.DataBind();
con.close();





Thanks & Regards,
Sasi Prabhu.
Author: Ravi Ranjan Kumar             
Posted Date: June 29, 2011     Points: 20   

Try
SqlConnection con = new SqlConnection();
con.ConnectionString = "Data Source=yourDataSource;Initial Catalog =YourDatabaseName; uid= sa;pwd = Yourpassword";
SqlCommand cmd = new SqlCommand("YourCommand",con);
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = cmd;
DataSet ds = new DataSet();
da.Fill(ds, tbname);
DataTable dt = ds.Tables[tbname];
dataGridView1.DataSource = dt.DefaultView; // Binding Datagrid view to Datatable



Thanks & Regards
Ravi Ranjan Kumar
http://raviranjankr.wordpress.com


Post Reply

You must Sign In To post reply
 
 
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend