|
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);
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
|
|
|
|
|
In the following code I register for two events in the last two lines. The evnts fire for the first time the form is loaded but from the second time and on, events are not registered anymore. I tired different things like adding
dataGrid.Scroll -= new ScrollEventHandler(dataGrid_Scroll);
dataGrid.KeyPress -= new KeyPressEventHandler(dataGrid_KeyPress);
beofre assigning dataGrid to the new FinderDataGridView object but stil doesn't work.
I guess the question is what is the correct way of registering for events when you reassign an object to a new one?
Hopefully the question is clear
public void SetFinder(ComplexObject finderObject)
{
complexObject = finderObject;
view = complexObject[0].DefaultView;
initialFilter = view.RowFilter;
dataGrid = new FinderDataGridView(view, complexObject[0].QuickFinderColumns, complexObject);
dataGrid.ColumnHeadersVisible = false;
datagridSplit.Panel2.Controls.Add(dataGrid);
emptyTable = new DataTable();
foreach (DataColumn column in finderObject.Tables[0].Columns)
{
if (column.ColumnMapping == MappingType.Element)
{
emptyTable.Columns.Add(new DataColumn(column.ColumnName, column.DataType));
}
}
emptyDataGrid.DataSource = emptyTable;
emptyTable.Rows.Add(emptyTable.NewRow());
emptyTable.AcceptChanges();
dataGrid.Scroll += new ScrollEventHandler(dataGrid_Scroll);
dataGrid.KeyPress += new KeyPressEventHandler(dataGrid_KeyPress);
}
|
|
|
|
|
Hello,
~~~Johnny~~~ wrote: I tired different things like adding
dataGrid.Scroll -= new ScrollEventHandler(dataGrid_Scroll);
dataGrid.KeyPress -= new KeyPressEventHandler(dataGrid_KeyPress);
beofre assigning dataGrid to the new FinderDataGridView object but stil doesn't work.
Although, it is not solving your problem, you should always unregister the event like this, bevor creating a new instance, cause the old instance will not be cleared by the GC.
I think the problem could be that you are not removing the old dataGrid instance out of the datagridSplit.Panel2.Controls.
If your dataGrid instance has a dispose method, you also should call it.
Hope it helps!
All the best,
Martin
|
|
|
|
|
Question to anyone please. Is SQl Server express Edition read only from an application. Insert and Update doesn't work. I cannot find the answers anywhere.
thx
Nana
|
|
|
|
|
Agyeman wrote: Is SQl Server express Edition read only from an application
That woiuld make it pretty useless as a desktop database, wouldn't it?
Agyeman wrote: Insert and Update doesn't work
The problem is most assuredly with your code. It would help if you posted a segment of the code you're using to try and update the database.
|
|
|
|
|
Dave Kreskowiak wrote: That would make it pretty useless as a desktop database
No kidding
|
|
|
|
|
There is no difference between SQL server 2005 and SQL 2005 Express except for certain limitations in the database size and features. Other than that iit is a fully implemented SQL database
|
|
|
|
|
Agyeman wrote: Is SQl Server express Edition read only from an application
No. You can read and write with it.
Agyeman wrote: Insert and Update doesn't work
Like Dave said, problem may be in your SQL statement, go ahead and post your Insert and Update that aren't working...
|
|
|
|
|
sql server express edition is only made ready only if that is what your users rights have been defined as. You can set up your user rights anyway you want. Normally you should control access to your tables through stored procedures. So one stored procedure to read data from the table, a different stored procedure to insert, another stored procedure to update, finally a stored procedure to delete.
Ben
|
|
|
|
|
If I'm guessing right, you most probably have a buggy code that inserts/updates (or) the folder in which the database file (.mdf) is located is readonly.
If your database file is located in someplace other than the default SQL Server installation path, check the folder and file permissions.
This is a common issue in using the Express edition in ASP.NET for user management. So maybe you're stuck somewhere similar.
SG
|
|
|
|
|
I have a string array.
Say i am looking at strArray[10]
I would like to find out how many chars are in array element 10.
I tried the .Length method but that does not seem to work.
What would giv eme this result?
|
|
|
|
|
strArray[10].Length is what you want.
|
|
|
|
|
That does not seem to work for me.
I have some text say "THIS IS A GREAT DAY" in location strArray[10]
I would like to get DAY out of there so i grab the length, then use it in the substring function, to extract the last three chars from the last position.
This blows up
|
|
|
|
|
|
The length value that i get back is bigger than the scope for that element.
|
|
|
|
|
This works fine:
string[] test = new string[] {
"Hello World!",
"This is a great day"
};
MessageBox.Show(test[1].Substring(test[1].Length - 3, 3));
|
|
|
|
|
LCI wrote: this blows up
string test = "THIS IS A GREAT DAY";
string day = test.Substring(test.IndexOf("DAY"), 3);
That works just fine here.
|
|
|
|
|
That works fine provided that the string is constant. What i am attempting to accomplish is to get the last 3 chars no matter what.
So i do something like
end = strArray[10].Length;
string strText = strArray[10].SubString((end-3), 3);
The end value seems to be bigger than the scope for strArray[10]
|
|
|
|
|
LCI wrote: What i am attempting to accomplish is to get the last 3 chars no matter what.
What if it is shorter then 3?
Remember that in string indexing starts from zero.
|
|
|
|
|
Remember that character indexes are 0 based, where the length counting starts at 1. To give an example, the string "day" has a length of 3 right? But the last character index is 2, not 3! The reason is that character index is 0, so [0] is d, [1] is a, [2] is y.
if (strArray[10].Length >= 3)
{
int lastCharacterIndex = strArray.Length - 1;
string strText = strArray[10].SubString(lastCharacterIndex - 3, 3);
}
|
|
|
|
|
|
It is 85501rrA backwards.
led mike
|
|
|
|
|
|
|
"If Google can't find it, it doesn't exist"
|
|
|
|