JaimeJegonia
asked on
Why DataBind() is not Working but Read() do?
Dear Experts,
I just want to understand or to be enlightened why Databind() is not working in this procedure?
While using this instead of DataBind():
while ( DR.Read() )
{
DropDown.Items.Add( System.Convert.ToString( DR[ "Detail" ] ) );
}
It works.
Thanks,
Jimi J.
********************* CODES *************************
// Create Instance of Connection and Command Object
OleDbConnection myConnection = new OleDbConnection(Configurat ionSetting s.AppSetti ngs["Datab aseCRTP1"] );
OleDbCommand myCommand = new OleDbCommand("QSRSBals", myConnection);
// Mark the Command as a SPROC
myCommand.CommandType = CommandType.StoredProcedur e;
// Execute the command
DropDown.Items.Clear();
myConnection.Open();
DropDown.DataTextField = "Detail";
DropDown.DataValueField = "SRSDetID";
OleDbDataReader DR = myCommand.ExecuteReader( CommandBehavior.CloseConne ction );
DropDown.DataSource = DR;
DropDown.DataBind();
//while ( DR.Read() )
//{
// DropDown.Items.Add( System.Convert.ToString( DR[ "Detail" ] ) );
//}
DropDown.Items.Insert(0,"- Pick-");
DropDown.SelectedIndex = 0;
DR.Close();
myConnection.Close();
I just want to understand or to be enlightened why Databind() is not working in this procedure?
While using this instead of DataBind():
while ( DR.Read() )
{
DropDown.Items.Add( System.Convert.ToString( DR[ "Detail" ] ) );
}
It works.
Thanks,
Jimi J.
********************* CODES *************************
// Create Instance of Connection and Command Object
OleDbConnection myConnection = new OleDbConnection(Configurat
OleDbCommand myCommand = new OleDbCommand("QSRSBals", myConnection);
// Mark the Command as a SPROC
myCommand.CommandType = CommandType.StoredProcedur
// Execute the command
DropDown.Items.Clear();
myConnection.Open();
DropDown.DataTextField = "Detail";
DropDown.DataValueField = "SRSDetID";
OleDbDataReader DR = myCommand.ExecuteReader( CommandBehavior.CloseConne
DropDown.DataSource = DR;
DropDown.DataBind();
//while ( DR.Read() )
//{
// DropDown.Items.Add( System.Convert.ToString( DR[ "Detail" ] ) );
//}
DropDown.Items.Insert(0,"-
DropDown.SelectedIndex = 0;
DR.Close();
myConnection.Close();
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Desp,
I think both DataValueField and DataTextField are assigned with appropriate values as follows:
DropDown.DataTextField = "Detail";
DropDown.DataValueField = "SRSDetID";
Jimi J
I think both DataValueField and DataTextField are assigned with appropriate values as follows:
DropDown.DataTextField = "Detail";
DropDown.DataValueField = "SRSDetID";
Jimi J
ASKER
igor_alpha
I tried your revised code. The same error (Page can't be displayed or stack oveflow...)
BTW, I'm executing this procedure to override the field control initialization.
Jimi J.
I tried your revised code. The same error (Page can't be displayed or stack oveflow...)
BTW, I'm executing this procedure to override the field control initialization.
Jimi J.
ASKER
Actually, i just sticked to datareader and sorted with other alternative to come up with a result i desired.
Somehow, they gave me also ideas...
Thanks guys.
You are not making use iof DataValueField and DatatextField properties
********************* CODES *************************
// Create Instance of Connection and Command Object
OleDbConnection myConnection = new OleDbConnection(Configurat
OleDbCommand myCommand = new OleDbCommand("QSRSBals", myConnection);
// Mark the Command as a SPROC
myCommand.CommandType = CommandType.StoredProcedur
// Execute the command
DropDown.Items.Clear();
myConnection.Open();
DropDown.DataTextField = "Detail";
DropDown.DataValueField = "SRSDetID";
OleDbDataReader DR = myCommand.ExecuteReader( CommandBehavior.CloseConne
DropDown.DataSource = DR;
DropDown .DataTextField = "Detail";
DropDown.DataValueField = "ENTER_KEY_VALUE_HERE";
DropDown.DataBind();
//while ( DR.Read() )
//{
// DropDown.Items.Add( System.Convert.ToString( DR[ "Detail" ] ) );
//}
DropDown.Items.Insert(0,"-
DropDown.SelectedIndex = 0;
DR.Close();
myConnection.Close();