无法将类型“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 ();
}

}
}
...全文
697 11 打赏 收藏 转发到动态 举报
写回复
用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 );
附登陆代码: using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; using System.Data.SqlClient; namespace 图书馆管理信息系统 { /// /// Form1 的摘要说明。 /// public class login : System.Windows.Forms.Form { private System.Windows.Forms.Label label1; private System.Windows.Forms.Label label2; private System.Windows.Forms.Label label3; private System.Windows.Forms.Button button1; private System.Windows.Forms.Button button2; private System.Windows.Forms.Button button3; private System.Windows.Forms.TextBox userid; private System.Data.SqlClient.SqlConnection sqlConnection1; private System.Data.SqlClient.SqlDataAdapter sqlDataAdapter1; private System.Data.SqlClient.SqlCommand sqlSelectCommand1; private System.Data.SqlClient.SqlCommand sqlInsertCommand1; private System.Data.SqlClient.SqlCommand sqlUpdateCommand1; private System.Data.SqlClient.SqlCommand sqlDeleteCommand1; private 图书馆管理信息系统.DataSet1 dataSet11; private System.Windows.Forms.TextBox textboxpass; /// /// 必需的设计器变量。 /// private System.ComponentModel.Container components = null; public login() { // // Windows 窗体设计器支持所必需的 // InitializeComponent(); // // TODO: 在 InitializeComponent 调用后添加任何构造函数代码 // } /// /// 清理所有正在使用的资源。 /// protected override void Dispose( bool disposing ) { if( disposing ) { if (components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Windows 窗体设计器生成的代码 /// /// 设计器支持所需的方法 - 不要使用代码编辑器修改 /// 此方法的内容。 /// private void InitializeComponent() { System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(login)); this.label1 = new System.Windows.Forms.Label(); this.label2 = new System.Windows.Forms.Label();

62,074

社区成员

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

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

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

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