Click here to Skip to main content
15,927,347 members
Home / Discussions / C#
   

C#

 
AnswerRe: cannot convert from 'string' to 'AccountManagement.IAccount' Pin
Christian Graus14-May-07 11:36
protectorChristian Graus14-May-07 11:36 
GeneralRe: cannot convert from 'string' to 'AccountManagement.IAccount' Pin
Latheesan14-May-07 11:52
Latheesan14-May-07 11:52 
GeneralRe: cannot convert from 'string' to 'AccountManagement.IAccount' Pin
Christian Graus14-May-07 12:28
protectorChristian Graus14-May-07 12:28 
QuestionOutlook dev question Pin
szukuro14-May-07 10:27
szukuro14-May-07 10:27 
AnswerRe: Outlook dev question Pin
dotnetcdr16-May-07 0:04
dotnetcdr16-May-07 0:04 
GeneralRe: Outlook dev question Pin
szukuro16-May-07 0:28
szukuro16-May-07 0:28 
GeneralRe: Outlook dev question Pin
szukuro16-May-07 0:36
szukuro16-May-07 0:36 
Questionproblem to retrieve relational data from tables. [modified] Pin
hdv21214-May-07 10:26
hdv21214-May-07 10:26 
hi i have 3 tables : t_books,t_sessions,t_titles that has master/details relation together :

t_books(bookID(PK),bookName) -> master
t_sessions(sessionID(PK),bookID(FK),sessionName) -> details

t_sessions(sessionID(PK),bookID(FK),sessionName) -> master
t_titles(titleID(pk),sessionID(fk),titleName,text,footerPage) -> details


and in normal load data(when retrieve all data without any condition) it's work good, but when i retrieve data with condition, i recieved the

following error message :

This constraint cannot be enabled as not all values have corresponding parent values.

my code is here :
private void FillTreeView(string searchText)<br />
        {<br />
            SqlConnection con = new SqlConnection(Properties.Settings.Default.Database1ConnectionString);<br />
            SqlCommand cmd = new SqlCommand();<br />
            SqlDataAdapter adapter = new SqlDataAdapter();<br />
            cmd.CommandText = "select * from t_books where bookName like '%" + searchText + "%'";<br />
            cmd.Connection = con;<br />
            adapter.SelectCommand = cmd;<br />
            DataSet ds = new DataSet();<br />
<br />
            SqlCommand cmd2 = new SqlCommand();<br />
            SqlDataAdapter adapter2 = new SqlDataAdapter();<br />
            cmd2.CommandText = "select * from t_sessions where sessionName like '%" + searchText + "%'";<br />
            cmd2.Connection = con;<br />
            adapter2.SelectCommand = cmd2;<br />
<br />
            SqlCommand cmd3 = new SqlCommand();<br />
            SqlDataAdapter adapter3 = new SqlDataAdapter();<br />
            cmd3.CommandText = "select * from t_titles where titleName like '%" + searchText + "%'";<br />
            cmd3.Connection = con;<br />
            adapter3.SelectCommand = cmd3;<br />
<br />
            adapter.Fill(ds, "t_books");<br />
            adapter2.Fill(ds, "t_sessions");<br />
            adapter3.Fill(ds, "t_titles");<br />
<br />
            DataRelation dataRelation;<br />
            DataRelation dataRelation2;<br />
<br />
            DataColumn dc1 = ds.Tables["t_books"].Columns["bookID"];<br />
            DataColumn dc2 = ds.Tables["t_sessions"].Columns["bookID"];<br />
<br />
            DataColumn dc3 = ds.Tables["t_sessions"].Columns["sessionID"];<br />
            DataColumn dc4 = ds.Tables["t_titles"].Columns["sessionID"];<br />
<br />
            dataRelation = new DataRelation("Relation1", dc1, dc2);<br />
            dataRelation2 = new DataRelation("Relation2", dc3, dc4);<br />
            ds.Relations.Add(dataRelation);<br />
            ds.Relations.Add(dataRelation2); //Error occured in this line<br />
            TreeNode book;<br />
            TreeNode session;<br />
            TreeNode title;<br />
<br />
            foreach (DataRow row in ds.Tables["t_books"].Rows)<br />
            {<br />
                book = new TreeNode(string.Format("{0}", (string)row["bookName"]));<br />
                book.Tag = row;<br />
                ds.Tables["t_sessions"].DefaultView.RowFilter = "bookID=" + row["bookID"];<br />
                for (int i = 0; i < ds.Tables["t_sessions"].DefaultView.Count; i++)<br />
                {<br />
                    DataRowView sessionRow = ds.Tables["t_sessions"].DefaultView[i];<br />
                    session = new TreeNode(string.Format("{0}", (string)sessionRow["sessionName"]));<br />
                    session.Tag = sessionRow;<br />
<br />
                    ds.Tables["t_titles"].DefaultView.RowFilter = "sessionID=" + sessionRow["sessionID"];<br />
                    for (int j = 0; j < ds.Tables["t_titles"].DefaultView.Count; j++)<br />
                    {<br />
                        DataRowView titleRow = ds.Tables["t_titles"].DefaultView[j];<br />
                        title = new TreeNode(string.Format("{0}", (string)titleRow["titleName"]));<br />
                        title.Tag = titleRow;<br />
<br />
                        session.Nodes.Add(title);<br />
                    }<br />
<br />
                    book.Nodes.Add(session);<br />
                }<br />
                this.treeView2.Nodes.Add(book);<br />
            }<br />
       }


how to solve my problem ? thanks


-- modified at 16:31 Monday 14th May, 2007
AnswerRe: problem to retrieve relational data from tables. Pin
Christian Graus14-May-07 10:42
protectorChristian Graus14-May-07 10:42 
Questionproblem to retrieve relational data from tables. Pin
hdv21214-May-07 10:23
hdv21214-May-07 10:23 
QuestionProblem with events Pin
~~~Johnny~~~14-May-07 8:50
~~~Johnny~~~14-May-07 8:50 
AnswerRe: Problem with events Pin
Martin#14-May-07 20:13
Martin#14-May-07 20:13 
QuestionSQl Server express Edition Pin
Agyeman14-May-07 8:47
Agyeman14-May-07 8:47 
AnswerRe: SQl Server express Edition Pin
Dave Kreskowiak14-May-07 8:56
mveDave Kreskowiak14-May-07 8:56 
GeneralRe: SQl Server express Edition Pin
Paul Conrad14-May-07 8:59
professionalPaul Conrad14-May-07 8:59 
AnswerRe: SQl Server express Edition Pin
~~~Johnny~~~14-May-07 8:57
~~~Johnny~~~14-May-07 8:57 
AnswerRe: SQl Server express Edition Pin
Paul Conrad14-May-07 8:58
professionalPaul Conrad14-May-07 8:58 
AnswerRe: SQl Server express Edition Pin
kubben14-May-07 9:01
kubben14-May-07 9:01 
AnswerRe: SQl Server express Edition Pin
SimulationofSai14-May-07 9:08
SimulationofSai14-May-07 9:08 
QuestionEnd of a string array element Pin
LCI14-May-07 6:11
LCI14-May-07 6:11 
AnswerRe: End of a string array element Pin
Ed.Poore14-May-07 6:14
Ed.Poore14-May-07 6:14 
GeneralRe: End of a string array element Pin
LCI14-May-07 6:22
LCI14-May-07 6:22 
GeneralRe: End of a string array element Pin
Ed.Poore14-May-07 6:28
Ed.Poore14-May-07 6:28 
GeneralRe: End of a string array element Pin
LCI14-May-07 6:31
LCI14-May-07 6:31 
GeneralRe: End of a string array element Pin
Ed.Poore14-May-07 7:08
Ed.Poore14-May-07 7:08 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.