更新时间:2023-11-27 10:12:16
假设您的表单具有以下内容:
Assuming you have a Form with:
尝试一下:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
LoadCustomerOnCombo();
}
private void LoadCustomerOnCombo()
{
string strCon = Settings.Default.PID2dbConnectionString;
try
{
using (OleDbConnection conn = new OleDbConnection(strCon))
{
conn.Open();
string strSql = "SELECT forename &\" \" & surname AS FullName, surname FROM customer"; //WHERE [customerID] ='" + txtName.Text + "'";
OleDbDataAdapter adapter = new OleDbDataAdapter(new OleDbCommand(strSql, conn));
DataSet ds = new DataSet();
adapter.Fill(ds);
cboName.DataSource = ds.Tables[0];
cboName.DisplayMember = "FullName";
cboName.ValueMember = "surname";
}
}
catch (Exception ex)
{
txtName.Text = ex.Message;
Console.WriteLine(ex.Message);
}
}
}
如果可行,请告诉我如何
,在此处留下评论的位置,否则有任何错误,您会在文本框内看到。
If worked so please tell me how is the where, left commented at the moment, else there are any errors, you'll see inside the textbox.