我想搜索一下。我用c#连接MySQL数据库。以及何时将在表之间创建实体关系图。我想使用查询来查找该特定任务属于特定客户的客户手机。
我尝试这个。
MySqlConnection connection = new MySqlConnection(MyConnectionString);
connection.Open();
try
{
MySqlCommand cmd = connection.CreateCommand();
cmd.CommandText = "SELECT * FROM assignments WHERE assignments.Customer_ID = customers.Customer_ID;
//assignments and customers are tables
MySqlDataAdapter adap = new MySqlDataAdapter(cmd);
DataSet ds = new DataSet();
adap.Fill(ds);
dataGridView5.DataSource = ds.Tables[0].DefaultView;
}
catch (Exception)
{
//throw;
MessageBox.Show("Please complete correct the fields");
}
finally
{
if (connection.State == ConnectionState.Open)
{
connection.Clone();
}
}
谁能帮我?
最佳答案
您的查询似乎是错误的。您需要像这样正确连接表:
cmd.CommandText = "SELECT * FROM assignments
inner join Customers on assignments.Customer_ID = customers.Customer_ID";
关于c# - C#,如何使用查询进行搜索,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/29656834/