日期:2014-05-17  浏览次数:20521 次

ADO.NET来补充我点基础知识吧。
        public static DataSet GetDataSet(string stringSql)
        {
            DataSet ds = new DataSet();
            using (SqlConnection conn = new SqlConnection(connectionString))
            {
                SqlDataAdapter adapter = new SqlDataAdapter();
                adapter.SelectCommand = new SqlCommand(stringSql, conn);
                adapter.Fill(ds);
            }
            return ds;
        }
        public static int ExecuteScalar(string stringSql)
        {
            using (SqlConnection conn = new SqlConnection(connectionString))
            {
                using (SqlCommand cmd = new SqlCommand(stringSql, conn))
                {
                    try
                    {
                        conn.Open();
                        object obj = cmd.ExecuteScalar();
                        int i = Convert.ToInt32(obj);
                        return i;
                    }