无法将类型“System.Data.SqlClient.SqlConnection”隐式转换为“string"

yu6325862 2010-10-16 12:36:23
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;


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


SqlConnection strConl;
SqlCommand strCom;
string strCon = "Data Source=.;Database=master;Uid=sa;Pwd=yu";


protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
bind();
}

}

protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIndex;
bind();
}

protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
string strSql = "delete from ygInfo where id = '" + GridView1.DataKeys[e.RowIndex].Value.ToString() + "'";
strCon = new SqlConnection(strCon );
strCom = new SqlCommand (strSql ,strCon );
strCon .open();
strCom .EndExecuteNonQuery ();
strCon .close();
bind();
}
public void bind ()
{

string strSql = "select * from ygInfo";
strCon = new SqlConnection (strCon );
SqlDataAdapter da = new SqlDataAdapter (strSql ,strCon );
DataSet ds = new DataSet ();
strCon .open();
da.Fill (ds,ygInfo);
GridView1 .DataSource = ds;
GridView1 .DataKeyNames = new string []{"id"};
GridView1 .DataBind ();
}

}
}
...全文
732 11 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
请叫我小码哥 2010-10-16
  • 打赏
  • 举报
回复
 SqlConnection strConl;
SqlCommand strCom;
string strCon = "Data Source=.;Database=master;Uid=sa;Pwd=yu";


protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
bind();
}

}

protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIndex;
bind();
}

protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
string strSql = "delete from ygInfo where id = '" + GridView1.DataKeys[e.RowIndex].Value.ToString() + "'";
strConl = new SqlConnection(strCon);
strCom = new SqlCommand(strSql, strConl);
strConl.Open();
strCom.ExecuteNonQuery();
strConl.Close();
bind();
}
public void bind()
{

string strSql = "select * from ygInfo";
strConl = new SqlConnection(strCon);
SqlDataAdapter da = new SqlDataAdapter(strSql, strCon);
DataSet ds = new DataSet();
strConl.Open();
da.Fill(ds, "ygInfo");
GridView1.DataSource = ds;
GridView1.DataKeyNames = new string[] { "id" };
GridView1.DataBind();
}


楼主上哪copy的代码。
jlds123 2010-10-16
  • 打赏
  • 举报
回复
SqlConnection conn= new SqlConnection (strCon );
wuyq11 2010-10-16
  • 打赏
  • 举报
回复
using(SqlConnection Conn = new SqlConnection(strCon );
{
strCom = new SqlCommand (strSql ,Conn);
}

strConl = new SqlConnection (strCon );
dalmeeme 2010-10-16
  • 打赏
  • 举报
回复
string strSql = "select * from ygInfo";
strCon = new SqlConnection(strSql);
构造方法的参数应是strSql。
shirley9226 2010-10-16
  • 打赏
  • 举报
回复
你sqlconnection定义的是SqlConnection strConl;
而你获取链接的代码是:strCon = new SqlConnection(strCon );
肯定是提示这个错误啊,你代码错了
改成 strConl= new SqlConnection(strCon );
wangdj2 2010-10-16
  • 打赏
  • 举报
回复
SqlConnection strConl;
string strCon = "Data Source=.;Database=master;Uid=sa;Pwd=yu";
两个变量名称重复,重新命名其中的一个名字
wwfgu00ing 2010-10-16
  • 打赏
  • 举报
回复
SqlConnection con =new SqlConnection (constr);

SqlConmand cmd=new SqlConmand (sql,con);

SqlDataAdapter da=new SqlDataAdapter (cmd);
wwfgu00ing 2010-10-16
  • 打赏
  • 举报
回复
SqlConnection con =new SqlConnection (constr);

SqlConmand cmd=new SqlConmand (sql,con);

SqlDataAdapter da=new SqlDataAdapter (cmd);
chen_ya_ping 2010-10-16
  • 打赏
  • 举报
回复
strCon = new SqlConnection(strCon );
===》strConl= new SqlConnection(strCon );
Jinglecat 2010-10-16
  • 打赏
  • 举报
回复

strConl = new SqlConnection (strCon );
SqlDataAdapter da = new SqlDataAdapter (strSql ,strConl );

62,243

社区成员

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

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

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

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