骄傲小公主

导航

C# sql操作

          SqlConnection con = new SqlConnection(strSqlConnection);//strSqlConnection为字符串连接
          DataTable dtRet = new DataTable();
          try
          {
              con.Open();
              SqlDataAdapter sda = new SqlDataAdapter(strQuery, con);//strQuery为sql语句
              if (sda != null)
              {
                  sda.Fill(dtRet);
              }

          }
          catch (Exception ex)
          {
                 dtRet = null;
          }
          finally
          {
              if (con.State == ConnectionState.Open)
                  con.Close();
          }
          return dtRet;

posted on 2014-07-06 17:27  骄傲小公主  阅读(138)  评论(0编辑  收藏  举报