在文本框中显示数据库

时间:2018-03-25 00:55:10

标签: c# sql-server

我尝试更改搜索时遇到问题

  • 我有一个组合框,其中的项目会更改textbox2中的文字
  • TextBox2.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());
}

当我使用表的固定名称时,它工作正常。

例如

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());
}

3 个答案:

答案 0 :(得分:0)

您添加了额外的'

SqlDataAdapter SDA = new SqlDataAdapter("Select Name,Phone from "+textBox2.Text+" where Name='" + textBox1.Text + "' ", con);

答案 1 :(得分:0)

您需要删除60.0b6表上的'信号引号。

From

而不是

"Select Name,Phone from "+textBox2.Text+" where Name='" + textBox1.Text + "' "

答案 2 :(得分:0)

使用此代码段替换您的代码。它应该适合你。还有额外的'在您的选择中

AttributeError: 'Series' object has no attribute 'to_pydatetime'
相关问题