asp.net 3.5中 connectionstring 里的 name 是什么
如我的webconfig里有<configuration><appSettings/><connectionStrings><addname="dingxiConnect...
如
我的webconfig里有
<configuration>
<appSettings/>
<connectionStrings>
<add name="dingxiConnectionString" connectionString="Data Source=5288005ac55345f.;Initial Catalog=dingxi;User ID=sa"
providerName="System.Data.SqlClient" />
</connectionStrings> 展开
我的webconfig里有
<configuration>
<appSettings/>
<connectionStrings>
<add name="dingxiConnectionString" connectionString="Data Source=5288005ac55345f.;Initial Catalog=dingxi;User ID=sa"
providerName="System.Data.SqlClient" />
</connectionStrings> 展开
2个回答
大雅新科技有限公司
2024-11-19 广告
2024-11-19 广告
这方面更多更全面的信息其实可以找下大雅新。深圳市大雅新科技有限公司从事KVM延长器,DVI延长器,USB延长器,键盘鼠标延长器,双绞线视频传输器,VGA视频双绞线传输器,VGA延长器,VGA视频延长器,DVI KVM 切换器等,优质供应商,...
点击进入详情页
本回答由大雅新科技有限公司提供
展开全部
public static string ConnString = ConfigurationManager.ConnectionStrings["dingxiConnectionString"].ConnectionString;
就是后台调用连接数据库的,很简单。
public static DataTable GetDataTable(string sql, SqlParameter[] sqlpar)
{
SqlConnection sqlcon = null;
try
{
sqlcon = new SqlConnection(ConnString);
sqlcon.Open();
SqlCommand sqlcom = new SqlCommand();
sqlcom.CommandText = sql;
sqlcom.Connection = sqlcon;
sqlcom.Parameters.AddRange(sqlpar);
SqlDataAdapter sqldata = new SqlDataAdapter();
sqldata.SelectCommand = sqlcom;
DataTable dt = new DataTable("newTable");
sqldata.Fill(dt);
sqlcon.Close();
return dt;
}
catch (Exception ex)
{
throw ex;
}
finally
{
sqlcon.Close();
}
}
public static int ExecSQL(string sql, SqlParameter[] sqlpar)
{
SqlConnection sqlcon = null;
try
{
sqlcon = new SqlConnection(ConnString);
sqlcon.Open();
SqlCommand sqlcom = new SqlCommand();
sqlcom.CommandText = sql;
sqlcom.Connection = sqlcon;
sqlcom.Parameters.AddRange(sqlpar);
return sqlcom.ExecuteNonQuery();
}
catch (Exception ex)
{
throw ex;
}
finally
{
sqlcon.Close();
}
}
就是后台调用连接数据库的,很简单。
public static DataTable GetDataTable(string sql, SqlParameter[] sqlpar)
{
SqlConnection sqlcon = null;
try
{
sqlcon = new SqlConnection(ConnString);
sqlcon.Open();
SqlCommand sqlcom = new SqlCommand();
sqlcom.CommandText = sql;
sqlcom.Connection = sqlcon;
sqlcom.Parameters.AddRange(sqlpar);
SqlDataAdapter sqldata = new SqlDataAdapter();
sqldata.SelectCommand = sqlcom;
DataTable dt = new DataTable("newTable");
sqldata.Fill(dt);
sqlcon.Close();
return dt;
}
catch (Exception ex)
{
throw ex;
}
finally
{
sqlcon.Close();
}
}
public static int ExecSQL(string sql, SqlParameter[] sqlpar)
{
SqlConnection sqlcon = null;
try
{
sqlcon = new SqlConnection(ConnString);
sqlcon.Open();
SqlCommand sqlcom = new SqlCommand();
sqlcom.CommandText = sql;
sqlcom.Connection = sqlcon;
sqlcom.Parameters.AddRange(sqlpar);
return sqlcom.ExecuteNonQuery();
}
catch (Exception ex)
{
throw ex;
}
finally
{
sqlcon.Close();
}
}
追问
意思是说name的值随便用一个就可以了?想怎么起就怎么起
追答
对是可以的,但是要命名规范。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询