【问题标题】:need string name, why showing integer Value? [closed]需要字符串名称,为什么显示整数值? [关闭]
【发布时间】:2013-12-20 11:53:22
【问题描述】:

当我按下 gno 时,它会显示 gname。但目前它向我显示了一个钱 amonut 有什么问题

  protected void txtgno_TextChanged(object sender, EventArgs e)
            {
                string connectionString = ConfigurationManager.ConnectionStrings["CompanybookConnectionString"].ConnectionString;
                SqlConnection con = new SqlConnection(connectionString);
                SqlCommand cmd = new SqlCommand("SELECT * FROM tblNewgroup WHERE gno=@gno", con);
                cmd.Parameters.AddWithValue("@gno", txtgno.Text);
                using (con)
                {
                    con.Open();
                    Object result = cmd.ExecuteScalar();
                    if (result != null)
                        //   lblResult.Text = String.Format("{0:c}", result); 
                        txtgname.Text = String.Format("{0:c}", result);


                    // else
                    //   lblResult.Text = "No match!"; 
                }
            }

【问题讨论】:

  • 你的表的架构设计是什么`tblNewgroup? I if the first column is gno, thats why it is display gno`值。
  • 字符串结果 = cmd.ExecuteScalar().ToString();可能会帮助你
  • 它没有显示任何东西...

标签: c# asp.net database textbox dataset


【解决方案1】:

尝试在 SQL 查询中指定要返回的列名:

SqlCommand cmd = new SqlCommand("SELECT gname FROM tblNewgroup WHERE gno=@gno", con);

【讨论】:

  • 已更改但无法正常工作。
  • @user3064392 调试器中result的值是多少?
猜你喜欢
  • 1970-01-01
  • 2022-11-13
  • 2012-01-30
  • 1970-01-01
  • 1970-01-01
  • 2012-11-24
  • 1970-01-01
  • 2020-11-22
  • 2016-08-09
相关资源
最近更新 更多