数据库相关

Posted on 2018-08-08 11:15  杭州丑八怪  阅读(58)  评论(0编辑  收藏  举报

读取连接字符串:

public static string connectionString = ConfigurationSettings.AppSettings["ConnectionString"].ToString();

config:

<configuration>
  <appSettings>
    <add key="ConnectionString" value="Data Source=192.168.19.220;User ID=sa;Password=091019100;Initial Catalog=lookchem_sell;"/>
  </appSettings>
</configuration>

修改方法:

public bool _Update(int ID,string Text)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update Pro_Detail set ");
            strSql.Append("Specifications=@Value");
            strSql.Append(" where infoid=@infoid");
            SqlParameter[] parameters = {
                    new SqlParameter("@infoid", SqlDbType.Int,4),
                    new SqlParameter("@Value", SqlDbType.Text)
                    };
            parameters[0].Value = ID;
            parameters[1].Value = Text;
            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }