Click here to Skip to main content
15,942,330 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I want to bind the values in Listview depending on the following Scenario.

DATABASE STRUCTIRE:
AGE      SEX    DOCTORNAME    TABLETNAME
21       F        WILLIAM      CALBOL,DOL,XXX
22       M        XXXXX        LIVOGERN,DOLOX,XXX

I am selecting all the values from above table and bind it in the listview in below format:

LISTVIEW

AGE      SEX    DOCTORNAME    TABLETNAME
21       F        WILLIAM      CALBOL
21       F        WILLIAM      DOL
21       F        WILLIAM      XXX
22       M        XXXXX        LIVOGERN
22       M        XXXXX       DOLOX
22       M        XXXXX        XXX


From Db i want to spilt the TABLETNAME by "," and displayed it in single row of list. In normal list view means i can select the values and bind it in depending on columname.Anyone help me to do this?
Posted
Updated 29-Sep-14 20:57pm
v2
Comments
Mukul Lad 30-Sep-14 2:59am    
Hi Vinodhini,

From Db i want to spilt the TABLETNAME by "," and displayed it in single row of list. In normal list view means i can select the values and bind it in depending on columname.Anyone help me to do this?

I can't understand what you mean from the above lines. Can you please explain it.?

One way to do it is that you import the database in MS excel , then separate the TABLETNAME values by splitting columns using "data to columns with , delimiter" , then again creating a new DB with seperate TABLETNAMEs.

Alternatively, you can select Distinct TABLETNAMEs using SQL CHARINDEX
 
Share this answer
 
v2
C#
            OleDbConnection con = new OleDbConnection(DisConnection);
            con.Open();
            string selquery = "Select * from tblTablet";
            OleDbCommand cmd = new OleDbCommand(selquery, con);
            OleDbDataReader read = cmd.ExecuteReader();
            DataTable dat = new DataTable();
            dat.Columns.AddRange(new DataColumn[8] { 
new DataColumn("Sex",typeof(string)),
new DataColumn("Age",typeof(string)), 
new DataColumn("DoctorName",typeof(string))}                                                                      new DataColumn("Tablet",typeof(string))});
            while (read.Read())
            {

                string sex = read.GetValue(0).ToString();
                string age = read.GetValue(1).ToString();
                string Name= read.GetValue(2).ToString();
                string tablet= read.GetValue(3).ToString(); 
                string[] spilt=tablet.spilt(',');
                for(int i=0;i<spilt.length;i++)>
                {
                    dat.Rows.Add(sex,age,Name,spilt[i].ToString());
                }
            } 
   Listview1.DataSource=dat;            
   Listview1.DataBind();
 
Share this answer
 
You have solved this, but I would like to mention one point here.

The structure of Table is not correct. As you are having a 1:N Relationship with Doctor and Tablet, so you should another Table to handle this. No need to have a comma spearated column.

So, your new Table would look like...
DOCTORNAME    TABLETNAME
WILLIAM        CALBOL
WILLIAM        DOL
WILLIAM        XXX
XXXXX          LIVOGERN
XXXXX          DOLOX
XXXXX          XXX

It would be better, if you can store only the Ids, provided you have individual tables for them with an ID.
DOCTORID    TABLETID
   1            1
   1            2
   1            3
   2            4
   2            5
   2            3
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900