zoukankan      html  css  js  c++  java
  • C#的一些知识

    1、将小数截取到某位小数

    string  str=3.1415926

    string str1=Math.Round(decimal.Parse(str),2) ;//str1为3.14

    2、SQL语句操作数据库

        (1)向数据库中插入或更新

                        SqlConnection myCon = new SqlConnection();
                        myCon.ConnectionString = "Data Source=.;Initial Catalog=JSManager;Integrated Security=True";
                        myCon.Open();

                        SqlCommand myCmd = null;

                        strSql += " INSERT……”

                        myCmd = new SqlCommand(strSql, myCon);
                        myCmd.ExecuteNonQuery();

                        myCon.Close();

       (2)从数据库中查询

                        SqlCommand cmd = new SqlCommand();
                        cmd.Connection = myCon;
                        cmd.CommandText = "Select LogName from TAB_TeacherInfo where Name = '" + teacherName + "'";
                        cmd.CommandType = CommandType.Text;
                        SqlDataAdapter da = new SqlDataAdapter(cmd);
                        da.MissingMappingAction = MissingMappingAction.Passthrough;
                        DataTable dt = new DataTable();
                        da.Fill(dt);//这样数据就存在了datatable中

       需要使用时即可从datatable中取, 如dt.Rows[0]["LogName"].ToString()取的即是表中LogName列;dt.Rows.Count得到数据的条数。

  • 相关阅读:
    卖菜起家赚到100万,他怎样做到的?
    百万网站创始人,痴迷网络经营,成就创业梦想
    徐小平靠投资进行创业,他却格外与众不同
    金融专业学生收卖废品,做起了“破烂王”
    pod setup命令失败解决方法
    pod setup命令失败解决方法
    pod setup命令失败解决方法
    pod setup命令失败解决方法
    PHP的闭包和匿名函数
    PHP的闭包和匿名函数
  • 原文地址:https://www.cnblogs.com/qingxinblog/p/2834040.html
Copyright © 2011-2022 走看看