我尝试更改搜索时遇到问题
码:
SqlDataAdapter SDA = new SqlDataAdapter("Select Name,Phone from '"+textBox2.Text+"' where Name='" + textBox1.Text + "' ", con);
DataTable dt = new DataTable();
SDA.Fill(dt);
if (dt.Rows.Count == 1)
{
textBox3.Text = (dt.Rows[0][0].ToString());
}
当我使用表的固定名称时它工作正常。
例如
SqlDataAdapter SDA = new SqlDataAdapter("Select Name,Phone from Table where Name='" + textBox1.Text + "' ", con);
DataTable dt = new DataTable();
SDA.Fill(dt);
if (dt.Rows.Count == 1)
{
textBox3.Text = (dt.Rows[0][0].ToString());
}
你放置了额外的'
:
SqlDataAdapter SDA = new SqlDataAdapter("Select Name,Phone from "+textBox2.Text+" where Name='" + textBox1.Text + "' ", con);
您需要删除'
表上的From
信号引号。
"Select Name,Phone from "+textBox2.Text+" where Name='" + textBox1.Text + "' "
代替
"Select Name,Phone from '"+textBox2.Text+"' where Name='" + textBox1.Text + "' "
用此代码段替换您的代码。它应该适合你。在您的选择中有额外的'
SqlDataAdapter SDA = new SqlDataAdapter("Select Name,Phone from "+textBox2.Text+"' where Name='" + textBox1.Text + "' ", con);
DataTable dt = new DataTable();
SDA.Fill(dt);
if (dt.Rows.Count == 1)
{
textBox3.Text = (dt.Rows[0][0].ToString());
}