//This connection string is used to connect to database String strConnection = "Data Source=MYSYSTEM;Initial Catalog=MySamplesDB;Integrated Security=True"; //Establish SQL Connection SqlConnection con = new SqlConnection(strConnection); //Open database connection to connect to SQL Server con.Open(); //Data table is used to bind the resultant data DataTable dtusers = new DataTable(); // Create a new data adapter based on the specified query. SqlDataAdapter da = new SqlDataAdapter("Select * from User_Information", con); //SQl command builder is used to get data from database based on query SqlCommandBuilder cmd = new SqlCommandBuilder(da); //Fill data table da.Fill(dtusers); //assigning data table to Datagridview dataGridView1.DataSource = dtusers; //Resize the Datagridview column to fit the gridview columns with data in datagridview dataGridView1.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells); con.Close(); |
|
If you enjoyed this post, please support the blog below. It's FREE! Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email. |
|||
Subscribe by RSS
Subscribe by Email
|
|||
|
|

Subscribe by RSS
Subscribe by Email
30 comments :
thanks sir......
it helps me a lot.....
Thank you Sir....
Please sir try to provide more sample codes.
Thank`s for previous codes.
thanks a lot
-subodh
Hi Sir,
Could I attach your blog into my blog?
-subodh
hi subodh copying the content from this blog is not allowed
Thank You Suresh
This is nice post, thanks for sharing with us.
It's really helpful for me and this link
http://www.mindstick.com/Articles/37ced6f5-fa75-498d-9eb9-681993fe23be/?Data%20Grid%20View
also helped me to complete my task.
Thanks
Superb....:)
hi..
i tried this code but it is not binding values to the datagridview,displaying empty gridview.
set AutoGenerateColumns before binding to datasource
GV.AutoGenerateColumns = true;
how to move the single or multiple listitems from one listbox to another listbox using c#.net
and/or
how to move the single or multiple listitems from one gridview to another listbox using c#.net
Check this post to move listitems from one listbox to another listbox http://www.aspdotnet-suresh.com/2010/12/how-to-move-listitems-from-one-listbox.html
kkk
but how to delete that selected value in that Grid ????
one form contain two grid view 1st grid view contain one column that column name is inventoryno,it is a primarykey if double clik one row in that grid view then based on inventoryno all data display in another grid view, after display in that 1st grid view selected row should be clear after saving/which row we selected in inventory column how to write this coding using WCF in ASP.NET(Windows based c#)
thank you......
how to add a row dynamically after pressing enter key in asp.net
How to update and also insert the data in this Grid from UI
exilent sir,i m so happy..
thanks sir................
Very insightful! Thanks, Sir!
can any body add combobox to datagrid and bind data in that combo...?
i used above method. but not desired output. when i debug, dataset gets filled, but i cant see on grid view... :(
try
{
MailMessage mail = new MailMessage();
SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");
// mail.From = new MailAddress(textBox2.Text);
mail.To.Add(dataGridView1.Rows[i].Cells["e_Mail"].ToString());
mail.Subject = textBox3.Text;
mail.Body = richTextBox1.Text;
SmtpServer.Port = 25;
SmtpServer.Credentials = new NetworkCredential("myemail@gmail.com", "password");
SmtpServer.EnableSsl = true;
SmtpServer.Send(mail);
MessageBox.Show("mail Send");
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
plz i send multiple mail, but not to add in email adddress of my datagrid view
it's a databind
help me
while scrolling rows of grid view are getting overlapped
thank you very much sir..your code helps me alot
Hi its a nice blog!!1
sir i have binded datagridview with dataset(using database commands , plz can u help me that how can i pick few rows from that datagridview using check boxes and put them into another table in database..in application regarding Purchase and Purchase Return
thank you
hai sir,... i tried this code. bt i cant use 'datatable'..getting this error ---> " The type or namespace name 'DataTable' could not be found (are you missing a using directive or an assembly reference?) "
please help me...what can i do ? im a child in asp.net. pls reply me.... thanku....
I have solve the Datagridview problem, thanks!