我在数据库中作为3个表:检索数据
- 的Emp(姓名,cellnumber,付款,Joining_date)
- Addmoney(姓名,date_of money_taken,类型)
- ADDDATE(姓名,Leaving_Date)
我希望只显示这些从这些3表中的列(名称,付款,Date_of_money_Taken,Joining_date,Leaving_date)所示,当用户输入存储在EMP表在TextBox任何名称,我在下面的代码中遇到问题。这是引发此:
Exception({"The multi-part identifier \"name.Text\" could not be bound."})
private void ShowEmp_Load(object sender, EventArgs e)
{
// create the connection string
connectionString = GetConnectionString();
connection = new SqlConnection(connectionString);
queryString = "select Emp.name,Emp.Payment,Emp.JoiningDate,Addm.Date,AddDate.LeavingDate from Emp,Addm,AddDate where name.Text='" + name + " ' ";// Select * From Emp
// create an SqlDataAdapter to execute the query
dAdapter = new SqlDataAdapter(queryString, connection);
// create a command builder
cBuilder = new SqlCommandBuilder(dAdapter);
// create a datatable to hold query results
dTable = new DataTable();
// fill DataTable
dAdapter.Fill(dTable);<-EXCEPTION({"The multi-part identifier \"name.Text\" could not be bound."})
// the DataGridView
//DataGridView dataGridView1 = new DataGridView();
// BindingSource to sync DataTable and DataGridView
bSource = new BindingSource();
// set the BindingSource DataSource
bSource.DataSource = dTable;
// set the DataGridView DataSource
dataGridView1.DataSource = bSource;
}
我注意到,这种方法是所有内部的'加载'事件处理程序,所以它只会被加载调用一次,这是所需的效果还是你想查找发生在按钮点击或类似的东西? – Coops