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;

你可能感兴趣的:(sql)