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

  • Thread starter Vigneshwar Pilli via DotNetMonster.com
  • Start date
V

Vigneshwar Pilli via DotNetMonster.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.Items.FindByValue(dr
["Lstate"].ToString().Trim()));
SClassification.SelectedIndex=SClassification.Items.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.IndexOf
(SchoolState.Items.FindByValue(dr["SchoolState"].ToString()));
ProgType.SelectedIndex=ProgType.Items.IndexOf(ProgType.Items.FindByValue(dr
["ProgType"].ToString().Trim()));
StayType.SelectedIndex=StayType.Items.IndexOf(StayType.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.IndexOf
(AwardWilling.Items.FindByValue(dr["AwardWilling"].ToString().Trim()));
USCitizen.SelectedIndex=USCitizen.Items.IndexOf(USCitizen.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(connectionString1);
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.
 
P

Prodip Saha

Vigneshwar Pilli via DotNetMonster.com said:
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.Items.FindByValue(dr
["Lstate"].ToString().Trim()));
SClassification.SelectedIndex=SClassification.Items.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.IndexOf
(SchoolState.Items.FindByValue(dr["SchoolState"].ToString()));
ProgType.SelectedIndex=ProgType.Items.IndexOf(ProgType.Items.FindByValue(dr
["ProgType"].ToString().Trim()));
StayType.SelectedIndex=StayType.Items.IndexOf(StayType.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.IndexOf
(AwardWilling.Items.FindByValue(dr["AwardWilling"].ToString().Trim()));
USCitizen.SelectedIndex=USCitizen.Items.IndexOf(USCitizen.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(connectionString1);
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.
 
P

Prodip Saha

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 said:
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.Items.FindByValue(dr
["Lstate"].ToString().Trim()));
SClassification.SelectedIndex=SClassification.Items.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.IndexOf
(SchoolState.Items.FindByValue(dr["SchoolState"].ToString()));
ProgType.SelectedIndex=ProgType.Items.IndexOf(ProgType.Items.FindByValue(dr
["ProgType"].ToString().Trim()));
StayType.SelectedIndex=StayType.Items.IndexOf(StayType.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.IndexOf
(AwardWilling.Items.FindByValue(dr["AwardWilling"].ToString().Trim()));
USCitizen.SelectedIndex=USCitizen.Items.IndexOf(USCitizen.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(connectionString1);
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.
 
V

Vigneshwar Pilli via DotNetMonster.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
 
P

Prodip Saha

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

Thanks,

Prodip
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top