ConfigurationManager.ConnectionStrings[]
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ConfigurationManager.ConnectionStrings[]相关的知识,希望对你有一定的参考价值。
string settings = Convert.ToString(ConfigurationManager.ConnectionStrings["SqlServices"]);中ConfigurationManager.ConnectionStrings[]是做什么用的?SqlServices是表名还是数据库的名
SqlServices 是 配置文件里面ConnectionStrings节点的子节点<Add>的name属性值<Add name="SqlServices " ConnectionString="" >
ConfigurationManager.ConnectionStrings["SqlServices"]
用于获取<Add>节点里面的ConnectionString属性值 参考技术A ConfigurationManager.ConnectionStrings[]
本周总结
计划:一个星期左右
.开发
用户故事:作为一个观众,我希望能看到队员的成绩,能看到单局比分和总比分,以便更加关心排球的成绩
(2)生成设计文档:
(3)设计复审(和同学交流讨论)
(4)代码规范:无
(5)具体设计:
class SqlHelper
{
private static readonly string constr = ConfigurationManager.ConnectionStrings["connectionStr"].ConnectionSt
public static int ExecuteNonQuery(string sql, params SqlParameter[] pms)
{//使用using关键字定义一个范围,在范围结束时骸自动调用这个类实例的Dispose处理
using (SqlConnection con = new SqlConnection(constr))
{ //创建执行DSql命令对象
using (SqlCommand cmd = new SqlCommand(sql, con))
{
if (pms != null)
{
cmd.Parameters.AddRange(pms);
}
con.Open();
}
}
}
public static object ExecuteScalar(string sql, params SqlParameter[] pms)
{
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand(sql, con))
{
if (pms != null)
{
cmd.Parameters.AddRange(pms);
}
con.Open();
return cmd.ExecuteScalar();
}
}
}
//执行返回SqlDataReader
public static SqlDataReader ExecuteReader(string sql, params SqlParameter[] pms)
{
SqlConnection con = new SqlConnection(constr);
using (SqlCommand cmd = new SqlCommand(sql, con))
{
if (pms != null)
{
cmd.Parameters.AddRange(pms);
}
try
{
con.Open();
return cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection);
}
catch (Exception)
{
con.Close();
con.Dispose();
throw;
}
}
}
//执行返回DataTable
public static DataTable ExecuteDataTable(string sql, params SqlParameter[] pms)
{
DataTable dt = new DataTable();
using (SqlDataAdapter adapter = new SqlDataAdapter(sql, constr))
{
if (pms != null)
{
adapter.SelectCommand.Parameters.AddRange(pms);
}
adapter.Fill(dt);
}
return dt;
}
}
class Info
{
public string Name { get; set; }
public int First { get; set; }
public int Second { get; set; }
public int Third { get; set; }
public int Fourth { get; set; }
public int Fifth { get; set; }
public int Score { get; set; }
}
private void Select1_Click_1(object sender, EventArgs e)
{
string sql = "select * from Bifen where [email protected]";
SqlParameter[] paras = new SqlParameter[]
{
new SqlParameter("@Name",Name),
};
using (SqlDataReader reader = SqlHelper.ExecuteReader(sql, paras))
{
if (reader.Read())
{
Info bf = new Info();
bf.Name = (string)reader["Name"];
bf.Second = reader.GetInt32(1);
bf.Third = reader.GetInt32(2);
bf.Fourth = reader.GetInt32(3);
bf.Fifth = reader.GetInt32(4);
bf.Score = reader.GetInt32(5);
}
}
}
private void button1_Click(object sender, EventArgs e)
{
if(comboBox1.selectIndex==0)
{
txtbox1.Text = bf.first.ToString();
}
private void button1_Click(object sender, EventArgs e)
{
if (comboBox2.Text =="雷霆:快船"&&comboBox1.Text == "第一局") { textBox1.Text = "25:15"; }
if (comboBox2.Text =="雷霆:快船" && comboBox1.Text == "第二局") { textBox1.Text = "25:18"; }
if (comboBox2.Text =="雷霆:快船" && comboBox1.Text == "第三局") { textBox1.Text = "20:25"; }
if (comboBox2.Text =="雷霆:快船" && comboBox1.Text == "第四局") { textBox1.Text = "21:25"; }
if (comboBox2.Text =="雷霆:快船" && comboBox1.Text == "第五局") { textBox1.Text = "15:13"; }
}
private void button2_Click(object sender, EventArgs e)
{
if (comboBox2.Text == "雷霆:快船”) { textBox2.Text = "3:2"; }
if (comboBox2.Text == "雷霆:快船") { textBox2.Text = "3:1"; }
}
(6)代码复审:无
(7)测试:无
以上是关于ConfigurationManager.ConnectionStrings[]的主要内容,如果未能解决你的问题,请参考以下文章