By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,660 Members | 1,133 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,660 IT Pros & Developers. It's quick & easy.

Problem in displaying few fields......... using DATA READER.

P: n/a
Hey,

Well, I have a Problem.

I have designed a table which has few fields which are being declared in
the database of type ....
char of length 10.
and other fields with varchar 50 and datetime too.

Well, the Problem is I am not able to display the CHAR type FIELDS in the
form when I am trying to pull them from the database and show it in the
form,
where as I am able to see the values for the fields declared in VARCHAR (50)
, to the appropriate controls( I mean to say to the textbox or the drop
down box they are binded to).
I need to show even these, char type variable values too in the form fields
but these are not being displayed,
I changed these fields too to Varchar and tried, the data being entered
into the records after I changed to Varchar are being displayed but not the
data of the records which was stored as CHAR (10).

Well I need some kind of solution to fix this problem.

here is the code how I am doing that........
hey.. I tried this TRIM finally but even then the fields were not being
displayed.

string sql="Select * From Student_SDS Where SSN='" + Session["SSN"] + "'";
dbCommand1 = new SqlCommand (sql, dbConnection1);
dbConnection1.Open(); SqlDataReader dr = dbCommand1.ExecuteReader();
dr.Read();
THESE FIELDS ARE BEING DISPLAYED the datatypes of these are..VARCHAR(50)
LName.Text = Convert.ToString(dr["LName"]);
FName.Text= Convert.ToString(dr["FName"]);
MName.Text= Convert.ToString(dr["MName"]);
Lstate.SelectedIndex=Lstate.Items.IndexOf(Lstate.I tems.FindByValue(dr
["Lstate"].ToString().Trim()));
SClassification.SelectedIndex=SClassification.Item s.IndexOf
(SClassification.Items.FindByValue(dr["SClassification"].ToString()));

These Fields are not being Displayed, the datatype of these fields is CHAR
(10).
SchoolState.SelectedIndex=SchoolState.Items.IndexO f
(SchoolState.Items.FindByValue(dr["SchoolState"].ToString()));
ProgType.SelectedIndex=ProgType.Items.IndexOf(Prog Type.Items.FindByValue(dr
["ProgType"].ToString().Trim()));
StayType.SelectedIndex=StayType.Items.IndexOf(Stay Type.Items.FindByValue(dr
["StayType"].ToString().Trim()));
EnrollmentType.SelectedIndex=EnrollmentType.Items. IndexOf
(EnrollmentType.Items.FindByValue(dr["EnrollmentType"].ToString().Trim()));
EnrollmentTerm.SelectedIndex=EnrollmentTerm.Items. IndexOf
(EnrollmentTerm.Items.FindByValue(dr["EnrollmentTerm"].ToString()));
SDSApplied.SelectedIndex=SDSApplied.Items.IndexOf
(SDSApplied.Items.FindByValue(dr["SDSApplied"].ToString().TrimEnd()));
AwardWilling.SelectedIndex=AwardWilling.Items.Inde xOf
(AwardWilling.Items.FindByValue(dr["AwardWilling"].ToString().Trim()));
USCitizen.SelectedIndex=USCitizen.Items.IndexOf(US Citizen.Items.FindByValue
(dr["USCitizen"].ToString().TrimStart()));
ParentGrad.SelectedIndex=ParentGrad.Items.IndexOf

dr.Close();
dbConnection1.Close();
System.Data.SqlClient.SqlConnection dbConnection2 = new
System.Data.SqlClient.SqlConnection(connectionStri ng1);
System.Data.SqlClient.SqlCommand dbCommand2 = new
System.Data.SqlClient.SqlCommand();
dbConnection2.Open();
SqlDataReader dr1 = dbCommand2.ExecuteReader();
dr1.Read();
dr1.Close();
dbConnection2.Close();

well, I donot know whats the problem and,.. what thing I can try to show
these records, already a lot of data is being entered with the fields with
CHAR datatype, I can change the table structure and can see the records
being entered there onwards, but I have to show the fields of CHAR type
being declared tooooooo.

Please provide me some solution.

Thanks and Regards,
Viggi.

--
Message posted via http://www.dotnetmonster.com
Nov 19 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a

"Vigneshwar Pilli via DotNetMonster.com" <fo***@nospam.DotNetMonster.com>
wrote in message news:a3******************************@DotNetMonste r.com...
Hey,

Well, I have a Problem.

I have designed a table which has few fields which are being declared in
the database of type ....
char of length 10.
and other fields with varchar 50 and datetime too.

Well, the Problem is I am not able to display the CHAR type FIELDS in the
form when I am trying to pull them from the database and show it in the
form,
where as I am able to see the values for the fields declared in VARCHAR (50) , to the appropriate controls( I mean to say to the textbox or the drop
down box they are binded to).
I need to show even these, char type variable values too in the form fields but these are not being displayed,
I changed these fields too to Varchar and tried, the data being entered
into the records after I changed to Varchar are being displayed but not the data of the records which was stored as CHAR (10).

Well I need some kind of solution to fix this problem.

here is the code how I am doing that........
hey.. I tried this TRIM finally but even then the fields were not being
displayed.

string sql="Select * From Student_SDS Where SSN='" + Session["SSN"] + "'";
dbCommand1 = new SqlCommand (sql, dbConnection1);
dbConnection1.Open(); SqlDataReader dr = dbCommand1.ExecuteReader();
dr.Read();
THESE FIELDS ARE BEING DISPLAYED the datatypes of these are..VARCHAR(50)
LName.Text = Convert.ToString(dr["LName"]);
FName.Text= Convert.ToString(dr["FName"]);
MName.Text= Convert.ToString(dr["MName"]);
Lstate.SelectedIndex=Lstate.Items.IndexOf(Lstate.I tems.FindByValue(dr
["Lstate"].ToString().Trim()));
SClassification.SelectedIndex=SClassification.Item s.IndexOf
(SClassification.Items.FindByValue(dr["SClassification"].ToString()));

These Fields are not being Displayed, the datatype of these fields is CHAR
(10).
SchoolState.SelectedIndex=SchoolState.Items.IndexO f
(SchoolState.Items.FindByValue(dr["SchoolState"].ToString()));
ProgType.SelectedIndex=ProgType.Items.IndexOf(Prog Type.Items.FindByValue(dr ["ProgType"].ToString().Trim()));
StayType.SelectedIndex=StayType.Items.IndexOf(Stay Type.Items.FindByValue(dr ["StayType"].ToString().Trim()));
EnrollmentType.SelectedIndex=EnrollmentType.Items. IndexOf
(EnrollmentType.Items.FindByValue(dr["EnrollmentType"].ToString().Trim())); EnrollmentTerm.SelectedIndex=EnrollmentTerm.Items. IndexOf
(EnrollmentTerm.Items.FindByValue(dr["EnrollmentTerm"].ToString()));
SDSApplied.SelectedIndex=SDSApplied.Items.IndexOf
(SDSApplied.Items.FindByValue(dr["SDSApplied"].ToString().TrimEnd()));
AwardWilling.SelectedIndex=AwardWilling.Items.Inde xOf
(AwardWilling.Items.FindByValue(dr["AwardWilling"].ToString().Trim()));
USCitizen.SelectedIndex=USCitizen.Items.IndexOf(US Citizen.Items.FindByValue (dr["USCitizen"].ToString().TrimStart()));
ParentGrad.SelectedIndex=ParentGrad.Items.IndexOf

dr.Close();
dbConnection1.Close();
System.Data.SqlClient.SqlConnection dbConnection2 = new
System.Data.SqlClient.SqlConnection(connectionStri ng1);
System.Data.SqlClient.SqlCommand dbCommand2 = new
System.Data.SqlClient.SqlCommand();
dbConnection2.Open();
SqlDataReader dr1 = dbCommand2.ExecuteReader();
dr1.Read();
dr1.Close();
dbConnection2.Close();

well, I donot know whats the problem and,.. what thing I can try to show
these records, already a lot of data is being entered with the fields with
CHAR datatype, I can change the table structure and can see the records
being entered there onwards, but I have to show the fields of CHAR type
being declared tooooooo.

Please provide me some solution.

Thanks and Regards,
Viggi.

--
Message posted via http://www.dotnetmonster.com

Nov 19 '05 #2

P: n/a
It's hard to tell what's the exact problem without looking at the error
code(if any). As an alternative, you can convert the char columns to varchar
in the sql and it should work.

string sql="Select * From Student_SDS Where SSN='" + Session["SSN"] + "'";
to something like..
string sql="Select *, convert(varchar,char_field) converted_field From
Student_SDS Where SSN='" + Session["SSN"] + "'";

Thanks,
Prodip
www.aspnet4you.com

"Vigneshwar Pilli via DotNetMonster.com" <fo***@nospam.DotNetMonster.com>
wrote in message news:a3******************************@DotNetMonste r.com...
Hey,

Well, I have a Problem.

I have designed a table which has few fields which are being declared in
the database of type ....
char of length 10.
and other fields with varchar 50 and datetime too.

Well, the Problem is I am not able to display the CHAR type FIELDS in the
form when I am trying to pull them from the database and show it in the
form,
where as I am able to see the values for the fields declared in VARCHAR (50) , to the appropriate controls( I mean to say to the textbox or the drop
down box they are binded to).
I need to show even these, char type variable values too in the form fields but these are not being displayed,
I changed these fields too to Varchar and tried, the data being entered
into the records after I changed to Varchar are being displayed but not the data of the records which was stored as CHAR (10).

Well I need some kind of solution to fix this problem.

here is the code how I am doing that........
hey.. I tried this TRIM finally but even then the fields were not being
displayed.

string sql="Select * From Student_SDS Where SSN='" + Session["SSN"] + "'";
dbCommand1 = new SqlCommand (sql, dbConnection1);
dbConnection1.Open(); SqlDataReader dr = dbCommand1.ExecuteReader();
dr.Read();
THESE FIELDS ARE BEING DISPLAYED the datatypes of these are..VARCHAR(50)
LName.Text = Convert.ToString(dr["LName"]);
FName.Text= Convert.ToString(dr["FName"]);
MName.Text= Convert.ToString(dr["MName"]);
Lstate.SelectedIndex=Lstate.Items.IndexOf(Lstate.I tems.FindByValue(dr
["Lstate"].ToString().Trim()));
SClassification.SelectedIndex=SClassification.Item s.IndexOf
(SClassification.Items.FindByValue(dr["SClassification"].ToString()));

These Fields are not being Displayed, the datatype of these fields is CHAR
(10).
SchoolState.SelectedIndex=SchoolState.Items.IndexO f
(SchoolState.Items.FindByValue(dr["SchoolState"].ToString()));
ProgType.SelectedIndex=ProgType.Items.IndexOf(Prog Type.Items.FindByValue(dr ["ProgType"].ToString().Trim()));
StayType.SelectedIndex=StayType.Items.IndexOf(Stay Type.Items.FindByValue(dr ["StayType"].ToString().Trim()));
EnrollmentType.SelectedIndex=EnrollmentType.Items. IndexOf
(EnrollmentType.Items.FindByValue(dr["EnrollmentType"].ToString().Trim())); EnrollmentTerm.SelectedIndex=EnrollmentTerm.Items. IndexOf
(EnrollmentTerm.Items.FindByValue(dr["EnrollmentTerm"].ToString()));
SDSApplied.SelectedIndex=SDSApplied.Items.IndexOf
(SDSApplied.Items.FindByValue(dr["SDSApplied"].ToString().TrimEnd()));
AwardWilling.SelectedIndex=AwardWilling.Items.Inde xOf
(AwardWilling.Items.FindByValue(dr["AwardWilling"].ToString().Trim()));
USCitizen.SelectedIndex=USCitizen.Items.IndexOf(US Citizen.Items.FindByValue (dr["USCitizen"].ToString().TrimStart()));
ParentGrad.SelectedIndex=ParentGrad.Items.IndexOf

dr.Close();
dbConnection1.Close();
System.Data.SqlClient.SqlConnection dbConnection2 = new
System.Data.SqlClient.SqlConnection(connectionStri ng1);
System.Data.SqlClient.SqlCommand dbCommand2 = new
System.Data.SqlClient.SqlCommand();
dbConnection2.Open();
SqlDataReader dr1 = dbCommand2.ExecuteReader();
dr1.Read();
dr1.Close();
dbConnection2.Close();

well, I donot know whats the problem and,.. what thing I can try to show
these records, already a lot of data is being entered with the fields with
CHAR datatype, I can change the table structure and can see the records
being entered there onwards, but I have to show the fields of CHAR type
being declared tooooooo.

Please provide me some solution.

Thanks and Regards,
Viggi.

--
Message posted via http://www.dotnetmonster.com

Nov 19 '05 #3

P: n/a
Hey, Dude...
Well, I Didnt get the query solution u have suggested,

Can U make it clear with an example say,

the fields which are of char data type be.... Fname, Lname

can u put them in a proper query you were suggesting me to do,

please, I tried but was getting some error in the format, so please just
get me the proper QUERY.

THANSK AND regards,

viggi

--
Message posted via http://www.dotnetmonster.com
Nov 19 '05 #4

P: n/a
Here is an example-
declare @FName char(10)
select @FName='Vigneshwar[this portion will be trimed]'
select convert(varchar,@FName) FName

Thanks,

Prodip

"Vigneshwar Pilli via DotNetMonster.com" <fo***@DotNetMonster.com> wrote in
message news:00******************************@DotNetMonste r.com...
Hey, Dude...
Well, I Didnt get the query solution u have suggested,

Can U make it clear with an example say,

the fields which are of char data type be.... Fname, Lname

can u put them in a proper query you were suggesting me to do,

please, I tried but was getting some error in the format, so please just
get me the proper QUERY.

THANSK AND regards,

viggi

--
Message posted via http://www.dotnetmonster.com

Nov 19 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.