日期:2014-05-18 浏览次数:21023 次
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();
------解决方案--------------------
这不查出来了吗~
SqlConnection con = new Sqlconnection(connectionstring);
SqlCommand com = new SqlCommand(con,sql);
SqlReader reader = com.ExecuteReader();
reader里面就读出来了
------解决方案--------------------
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 { }
}