无法将类型“System.Data.SqlClient.SqlConnection”隐式转换为“string"
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 ();
}
}
}
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 ();
}
}
}
...全文
相关推荐
C#连接SQL Server数据库的实例讲解
所以首先要通过using System.Data.SqlClient命令引用命名空间,连接数据库之后,通过调用SqlConnection对象的Open方法打开数据库。
C#图片转换成二进制流并且保存到sql server数据库.pdf
下面是一个简单的示例代码:```csharpusing System.Data.SqlClient;// 创建SqlConnection对象SqlConnection conn = new SqlConnection
System.Data.ConstraintException(解决方案).md
注意区分`System.Data.ConstraintException`和其他类型的异常,如`System.Data.SqlClient.SqlException`,因为它们所代表的错误类型不同,对应的处理方式也可能不同
C#把图片转换成数据流存入数据库中再读出来变成图片
使用`System.Data.SqlClient.SqlCommand`和`SqlParameter`可以实现此操作:```csharpusing System.Data.SqlClient;public
C#查询SqlServer数据库并返回单个值的方法
如果项目中还没有引用,可以在项目中添加引用或者在`.csproj`文件中包含以下内容:```xml<PackageReference Include="System.Data.SqlClient" Version


