2016-05-04 2 views
0

DataGridView подключается к БД с помощью bindingSource.Отображение (фамилия, имя) в DataGridView

dataGridView1.DataSource = bindingSource1; 
    GetData("SELECT [last_name] + ', ' + [first_name] AS [NAME], patient_id AS [CHART#], birth_date AS [DOB] FROM patient"); 


    private void GetData(string selectCommand) 
    { 
     try 
     { 
      // Specify a connection string. Replace the given value with a 
      // valid connection string for a Northwind SQL Server sample 
      // database accessible to your system. 

      // Create a new data adapter based on the specified query. 
      dataAdapter = new OleDbDataAdapter(selectCommand, DQLCommon.ConnectionString); 

      // Create a command builder to generate SQL update, insert, and 
      // delete commands based on selectCommand. These are used to 
      // update the database. 
      OleDbCommandBuilder commandBuilder = new OleDbCommandBuilder(dataAdapter); 

      // Populate a new data table and bind it to the BindingSource. 
      DataTable table = new DataTable(); 
      table.Locale = System.Globalization.CultureInfo.InvariantCulture; 
      dataAdapter.Fill(table); 
      bindingSource1.DataSource = table; 
      DataGridViewColumn column1 = dataGridView1.Columns[0]; 
      column1.Width = Convert.ToInt16(Convert.ToDouble(dataGridView1.Width) * 0.5); 
      DataGridViewColumn column2 = dataGridView1.Columns[1]; 
      column2.Width = Convert.ToInt16(Convert.ToDouble(dataGridView1.Width) * 0.23); 
      DataGridViewColumn column3 = dataGridView1.Columns[2]; 
      column3.Width = Convert.ToInt16(Convert.ToDouble(dataGridView1.Width) * 0.27); 
     } 
     catch (OleDbException) 
     { 
      MessageBox.Show("Failed in loading patient list."); 
     } 
    } 

Я ожидал, что имя отображается как < Фамилия>, < имя>, но разделенных точкой (.) Не запятая (,) как показано на картинке.

Как я мог решить эту проблему?

ответ

1
GetData("SELECT [last_name] + ', ' + [first_name] AS [NAME], patient_id AS [CHART#], birth_date AS [DOB] FROM patient"); 

есть запятая в команде GetData. попробуйте использовать. :

GetData("SELECT [last_name] + '. ' + [first_name] AS [NAME], patient_id AS [CHART#], birth_date AS [DOB] FROM patient"); 
+0

Нет ничего плохого в данной запятой. – CathalMF

+0

@CathalMF, но он хочет, чтобы имена были разделены периодом, то зачем получать данные с запятой? – Giellez

+0

Ах, извините, я неправильно понял вопрос. Я расстегнул нижний предел – CathalMF

Смежные вопросы