【发布时间】:2011-08-10 13:55:30
【问题描述】:
我在数据库中有 3 个表:
- Emp(姓名,手机号码,付款,入职日期)
- Addmoney(name,date_of money_taken,Type)
- AddDate(name,Leaving_Date)
我只想显示这 3 个表中的这些列(名称、付款、Date_of_money_Taken、Joining_date、Leaving_date),当用户在 TextBox 中输入存储在 Emp 表中的任何名称时,我在下面的代码中遇到问题。它正在抛出这个:
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;
}
【问题讨论】:
-
我注意到这个方法都在'Load'事件处理程序中,所以它只会在加载时被调用一次,这是想要的效果还是你希望在按钮单击或类似的东西?
标签: c# sql datagridview