Protected void Page_Load (object sender, EventArgs e)
{
if (! IsPostBack)
{
//call CommonClass acquisition data sets the GetDataSet
The DataSet ds=dbObj. GetDataSet (" select * from tb_News where id='" + Request. The QueryString (" id ") + "' ", "tbNews");
DataRow [] row=ds. Tables [r]. "tbNews" Select ();
DBClass cs in this part of the
Public DataTable GetDataSet (string strSql, string TableName)
{
Ds=new DataSet ();
Try
{
MyConn=GetConnection ();//connected to the database
Adapt=new SqlDataAdapter (strSql, myConn);//instantiate the SqlDataAdapter class object
Adapt. The Fill (ds, TableName);//fill data set
Return the ds. Tables [TableName];//returns the data set DataSet table collection
}
The catch (Exception ex)
{
Throw new Exception (ex. The Message, the ex);
}
The finally
{//disconnected, release resources
MyConn. Close ();
Adapt the Dispose ();
Ds. The Dispose ();
MyConn. The Dispose ();
}
Super novice, looking at a book playing ~ don't know how to solve?
Have a great god can help once, add my QQ ah ~
CodePudding user response:
The
The DataSet ds=dbObj. GetDataSet (" select * from tb_News where id='" + Request. The QueryString (" id ") + "' ", "tbNews");
DataRow [] row=ds. Tables [r]. "tbNews" Select ();
Instead of
The DataTable dt=dbObj. GetDataSet (" select * from tb_News where id='" + Request. The QueryString (" id ") + "' ", "tbNews");
DataRow [] row=dt. The Select ();
Or
Public DataTable GetDataSet (string strSql, string TableName)
{
Ds=new DataSet ();
Try
{
MyConn=GetConnection ();//connected to the database
Adapt=new SqlDataAdapter (strSql, myConn);//instantiate the SqlDataAdapter class object
Adapt. The Fill (ds, TableName);//fill data set
Return the ds. Tables [TableName];//returns the data set DataSet table collection
Instead of
Public DataSet GetDataSet (string strSql, string TableName)
{
Ds=new DataSet ();
Try
{
MyConn=GetConnection ();//connected to the database
Adapt=new SqlDataAdapter (strSql, myConn);//instantiate the SqlDataAdapter class object
Adapt. The Fill (ds, TableName);//fill data set
Return the ds;//returns the data set DataSet table collection
According to you the name of the method, recommend the second, other
CodePudding user response:
The DataSet ds=dbObj. GetDataSet (" select * from tb_News where id='" + Request. The QueryString (" id ") + "' ", "tbNews");To the DataTable ds=dbObj. GetDataSet (" select * from tb_News where id='" + Request. The QueryString (" id ") + "' ", "tbNews");
CodePudding user response:
Your method return type is a DataTable, but you are using the DataSet to receiveCodePudding user response:
Suggest you go to check the difference between the datatable and dataset, will seconds to understandCodePudding user response:
The DataSet contains multiple DataTableIf you want to take the table requires that the DataSet ds=new DataSet ();
Ds. Tables int/string