编译器错误信息: CS0103: 当前上下文中不存在名称“myConnection”

magicevy 2007-05-09 04:52:35
using System;
using System.Data;
using System.Configuration;
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;

public partial class _Default : System.Web.UI.Page
{

protected void Button1_Click(object sender, EventArgs e)
{
string strConn = "server=Localhost;uid=sa;pwd=;database=dzmusic";
string strCmd="select count(*) from admin where Username ='"+ TextBox1.Text +"' and Password = '"+ TextBox2.Text +"'";
SqlConnection myConnect = new SqlConnection();
myConnection.ConnectionString=strConn;
myConnection.Command=new sqlCommand(strCmd,myConnection);
myCommand.Connection.open();

int flag=(int)myCommand.ExecuteScalar();
myConnection.Connection.Close();
if (flag>0)
{
Session["username"]=TextBox1.Text;
Response.Redirect("default2.aspx");
}
else
{
Lable1.Text="对不起!";
TextBox2.Text="";
}
}
}


怎么修改?using System.Data.SqlClient.SqlConnection怎么不能继承这个类?
...全文
1032 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
wjp8271 2007-05-09
  • 打赏
  • 举报
回复

SqlConnection myConnect = new SqlConnection();
myConnection.ConnectionString=strConn;//改为myConnect.ConnectionString=strConn;//
amandag 2007-05-09
  • 打赏
  • 举报
回复
SqlConnection myConnect = new SqlConnection();
myConnection.ConnectionString=strConn;
==========================================

楼主,你点不出来属性的时候代码就不用敲下去了...

还有,你这种判断存在典型的SQL注入漏洞
ProgramIsLife 2007-05-09
  • 打赏
  • 举报
回复
就是的啊,LZ你代码写错了,把myConnection写成了myConnect
bingchener 2007-05-09
  • 打赏
  • 举报
回复
款且你的写法格式还存在些小问题,介意看下msdn
bingchener 2007-05-09
  • 打赏
  • 举报
回复
SqlConnection myConnect = new SqlConnection();
你定义的是myConnect没有定义myConnection
lxmfll2000 2007-05-09
  • 打赏
  • 举报
回复
string connString = ConfigurationManager.ConnectionStrings["ConnectionString1"].ToString();
SqlConnection conn = new SqlConnection(connString);
conn.Open();
SqlCommand Cmd = new SqlCommand(SQL, conn);
SqlDataAdapter da = new SqlDataAdapter(Cmd);

62,039

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

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