ASP.NET学习社区ASP.NET学习区有问有答 师父们,帮我看下我这问题怎么解决呢:

1  /  1  页   1 跳转 查看:1080

师父们,帮我看下我这问题怎么解决呢:

师父们,帮我看下我这问题怎么解决呢:

师父们,帮我看下我这问题怎么解决呢:
本人在ASP.NET 2.0的数据库操作练习中写了如下代码,运行就出现了:异常详细信息: System.Data.SqlClient.SqlException: 列名 'myid' 无效。
高手们帮看下问题出在哪了,谢谢!
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using Microsoft.SqlServer.Server;

protected void Button1_Click(object sender, EventArgs e)
{
connc conncs = new connc();
SqlConnection con = new SqlConnection(conncs.connectionString);
int myid = Convert.ToInt32(TextBox2.Text);
string sql = "SELECT * from texttest2 where id=myid";
SqlCommand cmd = new SqlCommand(sql, con);
con.Open();
SqlDataReader reader = cmd.ExecuteReader();
if (reader.Read())
TextBox3.Text = reader.GetString(1);
else
Label1.Text = "sorry";

reader.Close();
con.Close();
}
 

回复:近日事情比较少,想收个徒弟,大家一起学习asp.net

呵呵,经高手指点,问题解决了.把
string sql = "SELECT * from texttest2 where id=myid";
改为string sql = "SELECT * from texttest2 where id='" + myid + "'";
就行了.
我也想拜师,我的QQ号是:317820873
 
1  /  1  页   1 跳转

版权所有 ASP.NET学习门户 2.0.1214   Sitemap  

返顶部