Click here to Skip to main content
15,920,603 members
Home / Discussions / C#
   

C#

 
GeneralRe: Multiple forms and datagridviews Pin
Henry Minute15-May-09 13:09
Henry Minute15-May-09 13:09 
GeneralRe: Multiple forms and datagridviews [modified] Pin
bwood202018-May-09 6:50
bwood202018-May-09 6:50 
GeneralRe: Multiple forms and datagridviews Pin
Henry Minute18-May-09 8:18
Henry Minute18-May-09 8:18 
GeneralRe: Multiple forms and datagridviews Pin
bwood202018-May-09 8:44
bwood202018-May-09 8:44 
GeneralRe: Multiple forms and datagridviews Pin
Henry Minute18-May-09 9:54
Henry Minute18-May-09 9:54 
GeneralRe: Multiple forms and datagridviews Pin
bwood202018-May-09 12:54
bwood202018-May-09 12:54 
GeneralRe: Multiple forms and datagridviews Pin
Henry Minute18-May-09 13:01
Henry Minute18-May-09 13:01 
GeneralRe: Multiple forms and datagridviews Pin
bwood202019-May-09 7:13
bwood202019-May-09 7:13 
Good afternoon Henry,

I have tried to run the query using datagridview1.DataSource but doesn't seem to be working. Here is the code I run for csv files. Note that this doesn't show the entire method. In this method there are connections for the other file types.

<pre>
else if (comboBox1.Text == ".csv")
                  {
                              //Get file path from textbox
                              String FilePath;
                              FilePath = textBox1.Text;

                              //Connect to csv file
                              String comString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Path.GetDirectoryName(FilePath) + @";Extended Properties=""Text;HDR=YES;FMT=Delimited;IMEX=1\""";

                              String strSql = "SELECT * FROM [" + Path.GetFileName(FilePath) + "]";
                              OleDbConnection conCSV = new OleDbConnection(comString);
                              conCSV.Open();
                              OleDbCommand dbCommand = new OleDbCommand(strSql, conCSV);
                              OleDbDataAdapter dAdapter = new OleDbDataAdapter(dbCommand);
                              DataTable dFill = new DataTable();
                              dAdapter.Fill(dFill);
                              conCSV.Close();
                              //create new dataTable and add new top row for new headers
                              DataTable newDataTable = new DataTable();

                              foreach (DataColumn col in dFill.Columns)
                              {
                                    try
                                    {
                                          newDataTable.Columns.Add(new DataColumn(col.ColumnName));

                                    }
                                    catch (Exception)
                                    {

                                    }
                              }
                              foreach (DataRow row in dFill.Rows)
                              {
                                    string[] rowarr = new string[dFill.Columns.Count];

                                    for (int k = 0; k &lt; dFill.Columns.Count; k++)
                                    {
                                          rowarr[k] = row[k].ToString();
                                    }
                                    newDataTable.Rows.Add(rowarr);

                              }


                              DataRow NewRow;
                              NewRow = newDataTable.NewRow();
                              newDataTable.Rows.InsertAt(NewRow, 0);
                              // Method to alternate row color
                              GetColors();
                             
                              bindingSource1.DataSource = newDataTable;
                              dataGridView1.DataSource = bindingSource1;

                              //Method to get combobox that holds new headers
                              GetColumnHeaders();

                          
                              for (int i = 0; i &lt; dataGridView1.Columns.Count; i++)
                              {
                                    dataGridView1.Columns[i].SortMode = DataGridViewColumnSortMode.NotSortable;
                                    dataGridView1.Columns[i].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
                              }
                       
                             
                  }
</pre>

This may seem elementary to you and the code may not be all that great but it does work. As I stated before I am new to programming. Usually I just work on the database side but I was given this project to create a prototype. Your help and patience is much appreciated.

Thank you,

Brenton
GeneralRe: Multiple forms and datagridviews [modified] Pin
Henry Minute19-May-09 8:33
Henry Minute19-May-09 8:33 
GeneralRe: Multiple forms and datagridviews Pin
bwood202019-May-09 9:22
bwood202019-May-09 9:22 
GeneralRe: Multiple forms and datagridviews Pin
Henry Minute19-May-09 10:52
Henry Minute19-May-09 10:52 
GeneralRe: Multiple forms and datagridviews Pin
bwood202019-May-09 12:36
bwood202019-May-09 12:36 
GeneralRe: Multiple forms and datagridviews Pin
Henry Minute19-May-09 13:48
Henry Minute19-May-09 13:48 
GeneralRe: Multiple forms and datagridviews Pin
bwood202020-May-09 10:02
bwood202020-May-09 10:02 
GeneralRe: Multiple forms and datagridviews Pin
Henry Minute20-May-09 10:14
Henry Minute20-May-09 10:14 
GeneralRe: Multiple forms and datagridviews Pin
Henry Minute20-May-09 10:19
Henry Minute20-May-09 10:19 
GeneralRe: Multiple forms and datagridviews Pin
bwood202021-May-09 6:25
bwood202021-May-09 6:25 
GeneralRe: Multiple forms and datagridviews Pin
Henry Minute21-May-09 7:01
Henry Minute21-May-09 7:01 
GeneralRe: Multiple forms and datagridviews Pin
bwood202021-May-09 8:48
bwood202021-May-09 8:48 
GeneralRe: Multiple forms and datagridviews Pin
Henry Minute21-May-09 9:08
Henry Minute21-May-09 9:08 
GeneralRe: Multiple forms and datagridviews Pin
bwood202021-May-09 9:54
bwood202021-May-09 9:54 
GeneralRe: Multiple forms and datagridviews Pin
Henry Minute21-May-09 10:42
Henry Minute21-May-09 10:42 
GeneralRe: Multiple forms and datagridviews Pin
bwood202021-May-09 13:01
bwood202021-May-09 13:01 
GeneralRe: Multiple forms and datagridviews Pin
Henry Minute22-May-09 9:59
Henry Minute22-May-09 9:59 
GeneralRe: Multiple forms and datagridviews Pin
Henry Minute22-May-09 10:05
Henry Minute22-May-09 10:05 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.