数据库表中有一项photoUrl,就是路径
SqlCommand cmd = new SqlCommand("selecet photoUrl from photo where photoID=" + id, con);
这样可以得到路径,我想用一个字符串保存路径,请问该怎么做,谢谢~

解决方案 »

  1.   

    这样?string url = table.Rows[0]["photoUrl"].ToString();
      

  2.   

    con.Open();
    SqlDataReader mydr=cmd.ExecuteReader();
    string url=mydr["photoUrl"].Tostring();
    mydr.Close();
    con.Close();
      

  3.   

    string url = Convert.ToString(cmd.ExecuteScalar()); 试试这个
      

  4.   

    上面都不行?那看看你的sql执行有没有结果了
      

  5.   

    DataSet ds = new DataSet();
            this.conn.Open();
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = this.conn;
            cmd.CommandText = "select * from s_option where option_id=" + ID.ToString();
            SqlDataAdapter sqlDA = new SqlDataAdapter(cmd);
            sqlDA.Fill(ds);
            this.conn.Close();
            return ds.Tables[0];