錯誤:SQL轉換爲INT錯誤
Conversion failed when converting the nvarchar value 'select TopicID from Topic where TopicName='Data Structure'' to data type int
代碼:
public void BindGridview()
{
string strConnString = ConfigurationManager.ConnectionStrings["infoConnectionString"].ConnectionString;
SqlConnection sqlcon = new SqlConnection(strConnString);
sqlcon.Open();
string strquery2 = "select TopicID from Topic where TopicName='" + ddltopic.SelectedItem.Text+ "'";
string strquery3 = "select i.name ,i.score from info as i,Topic as t where [email protected]";
SqlCommand cmd = new SqlCommand(strquery3,sqlcon);
cmd.Parameters.AddWithValue("@topicid",strquery2);
cmd.Connection = sqlcon;
SqlDataReader dr;;
this.GridView1.DataSource =cmd.ExecuteReader();
this.GridView1.DataBind();
sqlcon.Close();
}
}
誰能告訴我在哪裏,我錯了?任何幫助將不勝感激..請儘快回覆..在此先感謝..
「TopicID」的數據類型是什麼? – Rohit
@ user3048066:如果你想獲得TopicID值並傳遞給其他查詢存儲過程,我認爲是好的。 – VDN
[踢壞的習慣:使用舊式JOIN](http://sqlblog.com/blogs/aaron_bertrand/archive/2009/10/08/bad-habits-to-kick-using-old-style-joins。 aspx) - 用ANSI-** 92 ** SQL標準(超過** 20年**之前)停止使用舊式*逗號分隔的表*樣式列表 –