主题:无法将类型“System.Data.SqlClient.SqlCommand”隐式转换为“strin
大家帮帮忙啊!
我建立了一个类: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;
/// <summary>
///
/// Sqldata的摘要说明
/// </summary>
public class SqlData
{
private SqlConnection sqlcon;
private SqlCommand sqlcom;
private SqlDataAdapter sqldata;
#region
/// <summary>
/// 构造函数,初始化时连接数据库
/// </summary>
public SqlData()
{
sqlcon = new SqlConnection(ConfigurationManager.AppSettings["ConStr"]);
sqlcon.Open();
//
// TODO: 在此处添加构造函数逻辑
//
}
#endregion
#region
/// <summary>
/// 此方法用来执行SQL语句
/// </summary>
/// <param name="SqlCom">要执行的SQL语句</param>
/// <returns></returns>
public bool ExceSQL(string sqlcom)
{
43行 sqlcom = new SqlCommand(sqlcom, sqlcon);
try
{
sqlcom.ExecuteNonQuery();
return true;
}
catch
{
return false;
}
finally
{
sqlcon.Close();
}
}
#endregion
#region
/// <summary>
/// 此方法返回一介DataSet类型
/// </summary>
/// <param name="sqlcom">要执行的SQL语句</param>
/// <returns></returns>
public DataSet ExceDS(string sqlcom)
{
try
{
90行 sqlcom = new SqlCommand(sqlcom, sqlcon);
sqldata = new SqlDataAdapter();
sqldata.SelectCommand = sqlcom;
DataSet ds = new DataSet();
sqldata.Fill(ds);
return ds;
}
finally
{
sqlcon.Close();
}
}
#endregion
#region
/// <summary>
/// 此方法返回一个SqlDataReader类型的参数
/// </summary>
/// <param name="sqlcom"></param>
/// <returns></returns>
public SqlDataAdapter ExceRead(string sqlcom)
{
sqlcom = new SqlCommand(sqlcom, sqlcon);
SqlDataReader read = sqlcom.ExecuteReader();
return read;
}
#endregion
}
想通过前台绑定<%#getlist%>.前台代码为:
<%@ Page Language="C#" MasterPageFile="lbbs.master" AutoEventWireup="true" CodeFile="lutitles.aspx.cs" Inherits="Default2" Title="Untitled Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<table><tr><td style="width: 718px; height: 7px"></td></tr><tr><td style="width: 718px; height: 379px"><table><tr><td></td></tr><tr><td><%#Getlist %></td></tr></table></td></tr></table>
</asp:Content>
可是在浏时出现43行"无法将类型“System.Data.SqlClient.SqlCommand”隐式转换为“string”"
出现错误的是在:
43 sqlcom = new SqlCommand(sqlcom, sqlcon);
try
{
sqlcom.ExecuteNonQuery();
return true;
我建立了一个类: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;
/// <summary>
///
/// Sqldata的摘要说明
/// </summary>
public class SqlData
{
private SqlConnection sqlcon;
private SqlCommand sqlcom;
private SqlDataAdapter sqldata;
#region
/// <summary>
/// 构造函数,初始化时连接数据库
/// </summary>
public SqlData()
{
sqlcon = new SqlConnection(ConfigurationManager.AppSettings["ConStr"]);
sqlcon.Open();
//
// TODO: 在此处添加构造函数逻辑
//
}
#endregion
#region
/// <summary>
/// 此方法用来执行SQL语句
/// </summary>
/// <param name="SqlCom">要执行的SQL语句</param>
/// <returns></returns>
public bool ExceSQL(string sqlcom)
{
43行 sqlcom = new SqlCommand(sqlcom, sqlcon);
try
{
sqlcom.ExecuteNonQuery();
return true;
}
catch
{
return false;
}
finally
{
sqlcon.Close();
}
}
#endregion
#region
/// <summary>
/// 此方法返回一介DataSet类型
/// </summary>
/// <param name="sqlcom">要执行的SQL语句</param>
/// <returns></returns>
public DataSet ExceDS(string sqlcom)
{
try
{
90行 sqlcom = new SqlCommand(sqlcom, sqlcon);
sqldata = new SqlDataAdapter();
sqldata.SelectCommand = sqlcom;
DataSet ds = new DataSet();
sqldata.Fill(ds);
return ds;
}
finally
{
sqlcon.Close();
}
}
#endregion
#region
/// <summary>
/// 此方法返回一个SqlDataReader类型的参数
/// </summary>
/// <param name="sqlcom"></param>
/// <returns></returns>
public SqlDataAdapter ExceRead(string sqlcom)
{
sqlcom = new SqlCommand(sqlcom, sqlcon);
SqlDataReader read = sqlcom.ExecuteReader();
return read;
}
#endregion
}
想通过前台绑定<%#getlist%>.前台代码为:
<%@ Page Language="C#" MasterPageFile="lbbs.master" AutoEventWireup="true" CodeFile="lutitles.aspx.cs" Inherits="Default2" Title="Untitled Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<table><tr><td style="width: 718px; height: 7px"></td></tr><tr><td style="width: 718px; height: 379px"><table><tr><td></td></tr><tr><td><%#Getlist %></td></tr></table></td></tr></table>
</asp:Content>
可是在浏时出现43行"无法将类型“System.Data.SqlClient.SqlCommand”隐式转换为“string”"
出现错误的是在:
43 sqlcom = new SqlCommand(sqlcom, sqlcon);
try
{
sqlcom.ExecuteNonQuery();
return true;