我已經產生了MySQL查詢其給出了下面的輸出只選擇特定的列和ASP.NET
name club countryid positionId description playersId DeleteFlag totalClubs
Sidd qegvwrwrvbwrdb 9 4 dvwrd 17 0 rvwb
goals caps positionName countryName
1212 12 Angriff Chile
查詢:
select
a.*, p.positionName, c.countryname
from
soccerplayers a
left join
countries c on c.countryId = a.countryId
left join
positions p on p.positionId = a.positionId
where
a.DeleteFlag = 0
我只想名字,俱樂部介紹,總球杆,球,帽,positionName和國家名稱
C#代碼
string cs = ConfigurationManager.AppSettings["ConnectionString"];
MySqlConnection register = new MySqlConnection(cs);
register.Open();
MySqlCommand cmd = new MySqlCommand("select a.*,p.positionName,c.countryname from soccerplayers a left join countries c on c.countryId=a.countryId left join positions p on p.positionId=a.positionId where a.DeleteFlag=0", register);
MySqlDataAdapter dataadapter = new MySqlDataAdapter(cmd);
cmd.ExecuteNonQuery();
DataSet ds = new DataSet();
dataadapter.Fill(ds, "soccerplayers");
register.Close();
DataTable dt = new DataTable();
dt = ds.Tables["soccerplayers"];
foreach (DataRow dr in dt.Rows)
{
string name = dr[0].ToString();
string club = dr[1].ToString();
string country = dr[11].ToString();
string position = dr[10].ToString();
string TotalClubs = dr[7].ToString();
string description =dr[4].ToString();
string Goals = dr[8].ToString();
string caps = dr[9].ToString();
List<string> list = new List<string>();
list.Add(name);
list.Add(club);
list.Add(country);
list.Add(position);
list.Add(TotalClubs);
list.Add(Goals);
list.Add(caps);
list.Add(description);
}
GridView1.DataSource = list;
GridView1.DataBind();
你有什麼問題? –
我只想要名稱,俱樂部,說明,總分俱樂部,目標,大寫字母,位置名稱和國家名稱 –
它表示「在選定的數據源中找不到名稱爲'名稱'的字段或屬性。異常 –