.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 >> Windows Application >> Post New QuestionBookmark and Share Subscribe to Forum

auotgenerate columns-windows application

Posted By: Jayakumar     Posted Date: March 05, 2010    Points:2   Category :Windows Application
hi,

i had added three columns with my datagridview control.
Id, Name(linkview), City.

When i bound the datagridview with 3 columns,its getting binding.

but i getting extra three columns with same name.

how it can be avoided.

i have used this.datagridview.autogeneratecolumn=false;

but not working...

Responses
Author: Naresh             
Posted Date: March 05, 2010     Points: 5   

Hi JayaKumar,

In Property Window of datagrid , you will have a property, AutoGenerateColumns, There u can make it false.Then u will not get those extra columns.
or u see in propertybuilder-->Columns of datagrid you have added columns.





malathy.v

Thanks
Naresh
Author: Syed Shakeer Hussain             
Posted Date: March 05, 2010     Points: 5   

Hi jayaKumar,
can you send your code what you had written

Author: Syed Shakeer Hussain             
Posted Date: March 05, 2010     Points: 5   

Hi,
write dataGridView1.AutoGenerateColumns = false in your code

SqlCommand cmd1 = new SqlCommand(sql1, con1);
DataTable t = new DataTable();
SqlDataAdapter dr = new SqlDataAdapter(cmd1);
dr.Fill(t);

dataGridView1.AutoGenerateColumns = false;
this.dataGridView1.DataSource = t;


Author: Jayakumar             
Posted Date: March 05, 2010     Points: 5   

String connStr = "Data Source=HOME\\SQLEXPRESS;Initial Catalog=db;Persist Security Info=True;User ID=sa;Password=sa";

String sql = "Select SongId, SongTitle, FilmTitle from A where Actor= '" + textBox1.Text + "' ";
SqlConnection conn = new SqlConnection(connStr);
conn.Open();
SqlCommand com = new SqlCommand(sql, conn);
SqlDataAdapter da = new SqlDataAdapter(com);
DataSet ds = new DataSet();
da.Fill(ds, "A");
//this.dataGridView1.AutoGenerateColumns = true;
this.dataGridView1.DataSource = ds.Tables[0];;
conn.Close();
com.Dispose();

Author: Jayakumar             
Posted Date: March 05, 2010     Points: 5   

by doing this


i am not getting any values.
only empty values r shown,by putting that code b4 datasource....
what to do..

String connStr = "Data Source=HOME\\SQLEXPRESS;Initial Catalog=db;Persist Security Info=True;User ID=sa;Password=sa";

String sql = "Select SongId, SongTitle, FilmTitle from A where Actor= '" + textBox1.Text + "' ";
SqlConnection conn = new SqlConnection(connStr);
conn.Open();
SqlCommand com = new SqlCommand(sql, conn);
SqlDataAdapter da = new SqlDataAdapter(com);
DataSet ds = new DataSet();
da.Fill(ds, "A");
this.dataGridView1.AutoGenerateColumns = false;
this.dataGridView1.DataSource = ds.Tables[0];;
conn.Close();
com.Dispose();

Author: Syed Shakeer Hussain             
Posted Date: March 05, 2010     Points: 5   

Hi
SqlCommand com = new SqlCommand(sql, conn);
SqlDataAdapter da = new SqlDataAdapter(com);
DataSet ds = new DataSet();
da.Fill(ds, "A");
this.dataGridView1.AutoGenerateColumns = false;
this.dataGridView1.DataSource = ds.Tables[0];;
conn.Close();
com.Dispose();

Author: Jayakumar             
Posted Date: March 05, 2010     Points: 5   

i had updated the code at datasource and form_load also..

String connStr = "Data Source=HOME\\SQLEXPRESS;Initial Catalog=db;Persist Security Info=True;User ID=sa;Password=sa";
String sql = "Select SongId, SongTitle, FilmTitle from A where Actor= '" + textBox1.Text + "' ";
SqlConnection conn = new SqlConnection(connStr);
conn.Open();
SqlCommand com = new SqlCommand(sql, conn);
SqlDataAdapter da = new SqlDataAdapter(com);
DataSet ds = new DataSet();
da.Fill(ds, "A");
this.dataGridView1.AutoGenerateColumns = false;
this.dataGridView1.DataSource = ds.Tables[0];;
conn.Close();
com.Dispose();

Author: Syed Shakeer Hussain             
Posted Date: March 05, 2010     Points: 5   

Hi Jaykumar,

you told as :-by doing this
i am not getting any values.
only empty values r shown,by putting that code b4 datasource....
what to do..

Have you check your table.is there any data or not relating your query.
If there is no data in your table,no record will display in your datagrid.

(or)

try to take a new dataGrid(delete the datagrid) and add your code.



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