I have two tables and I want to search into them by using a TextBox
and this is my code but wrong hope to help me
我有两个表,我想用一个文本框搜索它们,这是我的代码,但希望错误地帮助我
string constring = "Data Source =.; initial Catalog = business; Integrated Security=SSPI;";
SqlConnection CN = new SqlConnection(constring);
DataTable dt = new DataTable();
if (txtID.Text.Trim() != "")
{
SqlDataAdapter sda = new SqlDataAdapter("select tab1.ID ,tab1.DATMOSTAND ,tab1.MONY ,tab2.BYAN ,tab2.MONY from MAL_ERTEBAT,tab2 where tab1.ID = tab2.EID = '" + txtID.Text + "'", CN);
sda.Fill(dt);
}
dataGridView1.DataSource = dt;
where tab1.ID = tab2.EID = '" + txtID.Text + "'" this is the error part the message is "in correct syntax near ="
tab1的地方。ID = tab2。EID = '" + txtID。文本+ "'"这是错误部分消息是"语法正确接近="
1 个解决方案
#1
0
Hope you are missing the alias
name:
希望您缺少别名:
Replace the above SqlDataAdapter
with:
将上面的SqlDataAdapter替换为:
SqlDataAdapter sda = new SqlDataAdapter("select tab1.ID ,tab1.DATMOSTAND ,tab1.MONY ,tab2.BYAN ,tab2.MONY from MAL_ERTEBAT tab1,tab2 where tab1.ID = tab2.EID = '" + txtID.Text + "'", CN);
#1
0
Hope you are missing the alias
name:
希望您缺少别名:
Replace the above SqlDataAdapter
with:
将上面的SqlDataAdapter替换为:
SqlDataAdapter sda = new SqlDataAdapter("select tab1.ID ,tab1.DATMOSTAND ,tab1.MONY ,tab2.BYAN ,tab2.MONY from MAL_ERTEBAT tab1,tab2 where tab1.ID = tab2.EID = '" + txtID.Text + "'", CN);