C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Code Snippets » Databinding »

bindinding datagridview in windows application


Posted Date: 25 Nov 2008    Resource Type: Code Snippets    Category: Databinding
Author: bobMember Level: Gold    
Rating: 1 out of 5Points: 5



Binding data gridview in windows application is different from gridview in asp.net,heres example for binding data gridview in desktop application

place a data gridview in your form and write following code in code behind


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace WindowsApplication2
{

public partial class Form1 : Form
{
SqlConnection con;
SqlDataAdapter da;
SqlCommandBuilder cmd;
DataRow row;
DataSet ds = new DataSet();
BindingSource bsourse = new BindingSource();
public Form1()
{
InitializeComponent();
}



private void Form1_Load(object sender, EventArgs e)
{
con = new SqlConnection("server=localhost;database=raja;integrated security=sspi");
da = new SqlDataAdapter("select * from ex", con);
cmd = new SqlCommandBuilder(da);
da.Fill(ds, "ex");
ds.Tables[0].Constraints.Add("pik", ds.Tables[0].Columns[0], true);

bsourse.DataSource = ds.Tables["ex"];
dataGridView1.DataSource = bsourse;
}
}
}





For more details, visit http://dotnetmaterial9.blogspot.com/2008/11/worked-code-for-reference.html



Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
Http://dotnetmaterial9.blogspot.com/2008/11/worked-code-for-reference.html  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Bind using collections
Previous Resource: Adding and binding dynamic webcontrols to web form from database
Return to Discussion Resource Index
Post New Resource
Category: Databinding


Post resources and earn money!
 
More Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use