无法连接SQL,在C#中open金蝶执行sql语句出错报错

我写的一段sql语句在SQL中显示,在C#的界面也显示,但是到了查询的时候,却提示错误!!急急
[问题点数:40分,结帖人mona_wy]
我写的一段sql语句在SQL中显示,在C#的界面也显示,但是到了查询的时候,却提示错误!!急急
[问题点数:40分,结帖人mona_wy]
不显示删除回复
显示所有回复
显示星级回复
显示得分回复
只显示楼主
本帖子已过去太久远了,不再提供回复功能。再次!“连接未关闭。连接的当前状态为已打开。” - C#当前位置:& &&&再次!“连接未关闭。连接的当前状态为已打开。”再次!“连接未关闭。连接的当前状态为已打开。”&&网友分享于:&&浏览:92次再次求助!“连接未关闭。连接的当前状态为已打开。”下边是全部代码,我实在整不了了[code=C#][/code]using Susing System.Dusing System.Cusing System.Wusing System.Web.Susing System.Web.UI;using System.Web.UI.WebCusing System.Web.UI.WebControls.WebPusing System.Web.UI.HtmlCusing System.Data.SqlCpublic partial class _Default : System.Web.UI.Page{ &
SqlConnection sms_ &
string sms_ &
protected void Page_Load(object sender, EventArgs e) &
string sms_connstr = &Data Source=9\\Initial Catalog=Integrated Security=True&; &
sms_conn = new SqlConnection(sms_connstr); &
protected void LinkButton1_Click(object sender, EventArgs e) &
string sqlstr = &select * from ziliao where taname='& + TextBox1.Text + &'and taname='& + TextBox2.Text + &'and myname='& + TextBox4.Text + &'and mycity='& + TextBox5.Text + &'&; &
SqlCommand cmd = new SqlCommand(sqlstr, sms_conn); &
sms_conn.Open(); &
SqlDataReader dr = cmd.ExecuteReader(); &
if (dr.Read() == true) &
Response.Write(&here&); &
sms_conn.Close(); &
sms_sqlstr = &insert into ziliao(myname,mycity,email,taname,tacity)values(& + TextBox1.Text + &,& + TextBox2.Text + &,& + TextBox3.Text + &,& + TextBox4.Text + &,& + TextBox5.Text + &)&; &
SqlCommand cmd2 = new SqlCommand(sms_sqlstr, sms_conn); &
sms_conn.Open(); &
cmd2.ExecuteNonQuery(); &
sms_conn.Close(); &
& }------解决方案--------------------
很混乱,sms_conn.Open应该只在一个地方调用,sms_conn.Close也是,这个提示应该是在else分支内产生的,在SqlDataReader dr = cmd.ExecuteReader()之前就已经open过一次了,然后在else里又open一次,当然会出这个错误,
------解决方案--------------------
using System.D
using System.C
using System.W
using System.Web.S
using System.Web.UI;
using System.Web.UI.WebC
using System.Web.UI.WebControls.WebP
using System.Web.UI.HtmlC
using System.Data.SqlC
public partial class _Default : System.Web.UI.Page
SqlConnection sms_
string sms_
protected void Page_Load(object sender, EventArgs e)
string sms_connstr = &Data Source=9\\Initial Catalog=Integrated Security=True&;
sms_conn = new SqlConnection(sms_connstr);
protected void LinkButton1_Click(object sender, EventArgs e)
sms_conn.Open();
string sqlstr = &select * from ziliao where taname='& + TextBox1.Text + &'and taname='& + TextBox2.Text + &'and myname='& + TextBox4.Text + &'and mycity='& + TextBox5.Text + &'&;
SqlCommand cmd = new SqlCommand(sqlstr, sms_conn);
SqlDataReader dr = cmd.ExecuteReader();
bool hd = dr.Read();
dr.Dispose();
Response.Write(&here&);
sms_sqlstr = &insert into ziliao(myname,mycity,email,taname,tacity)values(& + TextBox1.Text + &,& + TextBox2.Text + &,& + TextBox3.Text + &,& + TextBox4.Text + &,& + TextBox5.Text + &)&;
mandText = sms_
cmd.ExecuteNonQuery();
cmd.Dispose();
sms_conn.Close();
} 共&2&页:
12345678910
12345678910
12345678910 上一篇:下一篇:文章评论相关解决方案 12345678910 Copyright & &&版权所有二次元同好交流新大陆
扫码下载App
汇聚2000万达人的兴趣社区下载即送20张免费照片冲印
扫码下载App
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!&&|&&
LOFTER精选
网易考拉推荐
用微信&&“扫一扫”
将文章分享到朋友圈。
用易信&&“扫一扫”
将文章分享到朋友圈。
阅读(3570)|
用微信&&“扫一扫”
将文章分享到朋友圈。
用易信&&“扫一扫”
将文章分享到朋友圈。
历史上的今天
loftPermalink:'',
id:'fks_095068',
blogTitle:'C#(.net)中的一次连接数据库执行多条sql语句(两种方法)',
blogAbstract:'C#(.net)中的一次连接数据库执行多条sql语句(两种方法)日 星期五 16:32
第一种方法:
&&&&&&&&&&& string str=\"server=.;uid=pwd=111111;database=text_db\";//连接字符串
&&&&&&& SqlConnection SCON =//连接对象
&&&&&&& SqlCommand SCom=new SqlCommand();//命令对象
blogTag:'',
blogUrl:'blog/static/',
isPublished:1,
istop:false,
modifyTime:9,
publishTime:9,
permalink:'blog/static/',
commentCount:0,
mainCommentCount:0,
recommendCount:1,
bsrk:-100,
publisherId:0,
recomBlogHome:false,
currentRecomBlog:false,
attachmentsFileIds:[],
groupInfo:{},
friendstatus:'none',
followstatus:'unFollow',
pubSucc:'',
visitorProvince:'',
visitorCity:'',
visitorNewUser:false,
postAddInfo:{},
mset:'000',
remindgoodnightblog:false,
isBlackVisitor:false,
isShowYodaoAd:true,
hostIntro:'',
hmcon:'1',
selfRecomBlogCount:'0',
lofter_single:''
{list a as x}
{if x.moveFrom=='wap'}
{elseif x.moveFrom=='iphone'}
{elseif x.moveFrom=='android'}
{elseif x.moveFrom=='mobile'}
${a.selfIntro|escape}{if great260}${suplement}{/if}
{list a as x}
推荐过这篇日志的人:
{list a as x}
{if !!b&&b.length>0}
他们还推荐了:
{list b as y}
转载记录:
{list d as x}
{list a as x}
{list a as x}
{list a as x}
{list a as x}
{if x_index>4}{break}{/if}
${fn2(x.publishTime,'yyyy-MM-dd HH:mm:ss')}
{list a as x}
{if !!(blogDetail.preBlogPermalink)}
{if !!(blogDetail.nextBlogPermalink)}
{list a as x}
{if defined('newslist')&&newslist.length>0}
{list newslist as x}
{if x_index>7}{break}{/if}
{list a as x}
{var first_option =}
{list x.voteDetailList as voteToOption}
{if voteToOption==1}
{if first_option==false},{/if}&&“${b[voteToOption_index]}”&&
{if (x.role!="-1") },“我是${c[x.role]}”&&{/if}
&&&&&&&&${fn1(x.voteTime)}
{if x.userName==''}{/if}
网易公司版权所有&&
{list x.l as y}
{if defined('wl')}
{list wl as x}{/list}C#错误中出现这样的语句:上下文中不存在SqlHelper_百度知道
C#错误中出现这样的语句:上下文中不存在SqlHelper
welcome, username));, new SqlParameter(&
if (Convert.Redirect(&@name&#region
object result = sqlH 0)
Response.aspx&).ExecuteScalar(&quot.ToInt64(result) &select * from T_userName where UserName=@name&quot
如果不是静态类、你所声明的sqlHelper是否为静态类21,sqlHelper的大小写是否和声明的一样3、如果是静态类,是否有实例化sqlHelper对象的代码4
sqlHelper不是静态类,怎么解决?
不是静态类就实例化,在方法外面类里面声明实例化的对象sqlHelper sqlHelper =new sqlHelper();
其他类似问题
为您推荐:
sqlhelper的相关知识
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁其他回答(5)
上帝啊,你在哪儿,我完全不知道这个世界变成这样了,C#是啥语言,居然需要大神才懂得给数据库添加一个记录。
需要什么神才能解决呢,Thor, Odin, Jesus, Monkey Kong, Monk Tang?
还是我看错了,这个问题是经过DES\MD5加密过的,需要先解密一下?
园豆:21523
园豆:21523
//1.创建connection对象
//2.创建command对象
//3.打开connection对象
//4.通过command对象执行sql
//ExecuteNonQuery方法,用于增、删、改;
//本机 数据库Test windows身份验证
string conStr = "Data Source=.;Initial Catalog=TIntegrated Security=True";
//接收sql返回的结果
using (SqlConnection con=new SqlConnection(conStr))
//插入sql语句
string sqlStr = "insert into UserInfo(name,age)values('hello','23');";
using (SqlCommand cmd=new SqlCommand(sqlStr,con))
con.Open();
result=cmd.ExecuteNonQuery();
if (result&0)
Console.WriteLine("ok");
Console.WriteLine("error");
园豆:4620
我想说,你接收SQL的数据就确定是int类型的?
我已经解决了
你傻呀,没看到使用cmd.ExecuteNonQuery();接收返回值啊
&&&您需要以后才能回答,未注册用户请先。

我要回帖

更多关于 sql语句查错 的文章

 

随机推荐