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.");
}
}
我所期望的名稱顯示爲<姓>,<名>,而是由句點分隔(。)不是逗號(,)像下面的圖片。
我怎麼能解決這個問題?
在那裏逗號沒有任何問題。 – CathalMF
@CathalMF但他希望名稱被一個句點分隔,那麼爲什麼要用逗號獲取數據? – Giellez
對不起,我誤解了這個問題。我解開我的downvote – CathalMF