本文介绍了如何从2表中选择并使用mysqldatareader获取它们的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
上午好女士和先生。我想从表1中选择原因并从table2中选择地址,其中unique_id = @uniqueid。两个表都有名为unique_id的主键。并使用DataReader获取它们的价值。
我尝试过:
Good day Ma'am and Sir. I want to select cause from table 1 and select address from table2 where unique_id = @uniqueid. Both tables have primary key called unique_id. and get the their value using DataReader.
What I have tried:
using(MySqlConnection con = new MySqlConnection(connString))
{
consp.Open();
string clientid = "009";
MySqlDataReader reader;
MySqlCommand com = new MySqlCommand("SELECT FROM ",con);
com.Parameters.AddWithValue("@uniqueid,"clientid);
reader = com.ExecuteReader();
while(reader.HasRows && reader.Read())
{
string cause;
string address;
cause = reader.GetString(reader.GetOrdinal());
address = reader.GetString(reader.GetOrdinal());
}
}
推荐答案
MySqlCommand com = new MySqlCommand("SELECT clause, address FROM table1 JOIN table2 ON table1.unique_id = table2.unique_id WHERE table1.unique_id = @uniqueid",con);
这篇关于如何从2表中选择并使用mysqldatareader获取它们的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!