请问高手大吓,是用ODBC还是ado直接连sql server好呢?

解决方案 »

  1.   

     public DataSet getNum(int id)
            {
                using (SqlConnection con = new SqlConnection(@"Data Source=DEMO;Initial Catalog=DEMODB;Integrated Security=True"))
                {
                    string sql = "select person from MossApproveConfig where id= '" + id + "'";
                    DataSet ds = new DataSet();
                    SqlDataAdapter da = new SqlDataAdapter(sql, con);
                    da.Fill(ds, "Data");
                    con.Close();
                    return ds;
                }
            }
      

  2.   

    都可以,想追求新技术就用ado.net
      

  3.   

    ado.net好一些,dataadapter以及datareader都优化了很多
      

  4.   

    public int Insertyjlm(int yjlmbh,string yjlmmc,string yjlmms)
        {
            int i=0;
            SqlConnection myConnection = new SqlConnection(connectionString);
            SqlCommand myCommand = new SqlCommand();
            myCommand.Connection = myConnection;
            myCommand.CommandType = CommandType.StoredProcedure;
            myCommand.CommandText = "sp_insertyjlm";
            myCommand.Parameters.Add("@yjlmbh", SqlDbType.Int).Value = yjlmbh;
            myCommand.Parameters.Add("@yjlmmc", SqlDbType.VarChar, 20).Value = yjlmmc;
            myCommand.Parameters.Add("@yjlmms", SqlDbType.VarChar, 160).Value = yjlmms;
            myConnection.Open();
            try
            {
                i = myCommand.ExecuteNonQuery();
            }
            finally
            {
                myConnection.Close();
            }
            return i;
        }
        public DataTable getyjlmmc()
        {
            SqlConnection myConnection = new SqlConnection(connectionString);
            SqlCommand myCommand = new SqlCommand();
            myCommand.Connection = myConnection;
            myCommand.CommandType = CommandType.StoredProcedure;
            myCommand.CommandText = "sp_getyjlmmc";
            SqlDataAdapter myAdapter = new SqlDataAdapter(myCommand);
            DataTable dt = new DataTable();
            myAdapter.Fill(dt);
            return dt;
        }