我在數據庫中作爲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