sql = "select ParentId from Tab_System_Area where AreaId=" + Aid +"";各位大侠 如果 我要用到 ParentId 应该怎样提取出来 .. 麻烦给出详细的代码!
谢谢!

解决方案 »

  1.   

    你返回的是啥啊?  
    如果是一个DataTabledt.Rows[0]["ParentId"].ToString()
      

  2.   

    public string connectionString = "server=10.66.66.16;database=db;uid=sa;pwd=aa";
    public static DataSet Query(string SQLString)
            {
                using (SqlConnection connection = new SqlConnection(connectionString))
                {
                    DataSet ds = new DataSet();
                    try
                    {
                        connection.Open();
                        SqlDataAdapter command = new SqlDataAdapter(SQLString, connection);
                        command.Fill(ds, "ds");
                    }
                    catch (System.Data.SqlClient.SqlException ex)
                    {
                        throw new Exception(ex.Message);
                    }
                    return ds;
                }
            }
    string sql = "select ParentId from Tab_System_Area where AreaId=" + Aid +""; 
    dataset ds=Query(sql);
    string id= ds.datatables[0].rows[0]["ParentId"].tostring();改大小写
      

  3.   

    这不查出来了吗~
    SqlConnection con = new Sqlconnection(connectionstring);
    SqlCommand com = new SqlCommand(con,sql);
    SqlReader reader = com.ExecuteReader();
    reader里面就读出来了
      

  4.   

    try
                    {
                        sql = "select ParentId from Tab_System_Area where AreaId=" + Aid +"";                     SqlCommand cmd=new SqlCommand(sql,conn);
                        cmd.Connecction.Open();
                        SqlDataReader reader = cmd.ExecuteReader();
                         
                        if (reader.Read())
                        {
                         int id = (int)reader["ParentId "];
                          
                        }
                        reader.Close();                }
                    catch (Exception ex)
                    {
                        Logger.LogException(LogComponentConstants.SQLServer, ex.Message);
                    }
                    finally
                    {
                        try
                        {
                            conn.Close();
                        }
                        catch { }
                    }
      

  5.   

     protected void Button1_Click(object sender, EventArgs e)
        {
            string sql;        string Aid = this.TreeView1.SelectedValue;        string Areaname = this.TextBox1.Text;        sql = "select ParentId from Tab_System_Area where AreaId=" + Aid +"";        DataTable DT = new DataTable();        DT = ReadData(sql);        int pid = Convert.ToInt32(DT.Rows[0]["ParentId"]);
        
            sql = "insert into Tab_System_Area values('"+ Areaname +"',"+ pid +")";        dfun.ExecSQLDataResult(sql);        this.TextBox1.Text = null;        TreeView1.Nodes.Clear();
            
            CreateNode("0", (TreeNode)null);        TreeView1.ExpandAll();
        }
    datatable类:
     private DataTable ReadData(string sql)
        {
            DataSet ds = dfun.ExecSQLDataSet("select * from Tab_System_Area");        dt = ds.Tables[0];        this.TreeView1.DataBind();        return dt;
        }这样对吗?? 可是还是不行啊