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 "];
如果是一个DataTabledt.Rows[0]["ParentId"].ToString()
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里面就读出来了
{
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 { }
}
{
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;
}这样对吗?? 可是还是不行啊