高手指点我这段代码哪里有问题,并指出如何修改,谢谢

scdygwlj520 2009-03-26 01:52:07
private void button1_Click(object sender, EventArgs e)
{


SqlConnection con = new SqlConnection("server=.;database=dxdata;uid=sa;pwd= ");
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
string bh = textBox1.Text;
string sql = "select id,name,add from VIEW_db_Owner where id='" + bh + "'";
con.Open();
OdbcDataReader myread;
myread = con.ToString;
while(myread.Read())
{
textBox3.Text=myread.GetString(0);
textBox4.Text=myread.GetString(1);
comboBox1.Text=myread.GetString(2);

}

}
...全文
134 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
liu4545533 2009-03-26
  • 打赏
  • 举报
回复
[Quote=引用楼主 scdygwlj520 的帖子:]
private void button1_Click(object sender, EventArgs e)
{


SqlConnection con = new SqlConnection("server=.;database=dxdata;uid=sa;pwd= ");
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
string bh = textBox1.Text;
string sql = "select id,name,add from VIEW_db_Owner where id='" + bh + …
[/Quote]
myread里面根本就是空的 根本就没有查询数据
endlessw 2009-03-26
  • 打赏
  • 举报
回复
using System.data.Sqlclient;
scdygwlj520 2009-03-26
  • 打赏
  • 举报
回复


myread = cmd.ExecuterReader();改为此句后出现下面的错误提示呢:

错误 1 “System.Data.SqlClient.SqlCommand”不包含“ExecuterReader”的定义,并且找不到可接受类型为“System.Data.SqlClient.SqlCommand”的第一个参数的扩展方法“ExecuterReader”(是否缺少 using 指令或程序集引用?)
hlgchina 2009-03-26
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 zhoukang0916 的回复:]
C# code//好好去看看基础的ado.net
private void button1_Click(object sender, EventArgs e)
{
string bh = textBox1.Text;
string sql = "select id,name,add from VIEW_db_Owner where id='" + bh + "'";
SqlConnection con = new SqlConnection("server=.;database=dxdata;uid=sa;pwd= ");
SqlConnection connection= new SqlConnection(con);

[/Quote]


赞同,楼主的代码怎么看都像是asp的代码
PandaIT 2009-03-26
  • 打赏
  • 举报
回复
//好好去看看基础的ado.net
private void button1_Click(object sender, EventArgs e)
{
string bh = textBox1.Text;
string sql = "select id,name,add from VIEW_db_Owner where id='" + bh + "'";
SqlConnection con = new SqlConnection("server=.;database=dxdata;uid=sa;pwd= ");
SqlConnection connection= new SqlConnection(con);
con.Open();
SqlCommand cmd = new SqlCommand(sql,connection);

SqlDataReader myread=cmd.ExecuteReader();
while(myread.Read())
{
textBox3.Text=myread.GetString(0);
textBox4.Text=myread.GetString(1);
comboBox1.Text=myread.GetString(2);

}

}
hhlys 2009-03-26
  • 打赏
  • 举报
回复
OdbcDataReader myread;
myread = con.ToString;

楼主应该是这两句错了。
第一:OdbcDataReader 类用于与ODBC数据库打交道,从你其余代码来看,你现在是跟SQL数据库打交道,所以应该用SqlDataReader
第二:myread是OdbcDataReader 类型,myread = con.ToString;这句话明显不对;
应写为myread = cmd.ExecuterReader();
EveryCase 2009-03-26
  • 打赏
  • 举报
回复
你最好自己单步调试一下。看看哪里出的问题!!

111,126

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧