|
Thanks for your reply again, i tried to put it in, but it said the doFindAccount method is not found.
Even if i managed to get the method working, the problem is that, the doFindAccount searches for account in the hashtable. When im searching for the first time, this account name would not be in the hashtable.
So, i looked at my main form and found this code that adds new account:
IAccount account = new Account(nameTextBox.Text, "");<br />
account.SetAccNumber(nameTextBox.Text);<br />
doEditAccount(account);<br />
bank.AddAccount(account);
So, from that, i see, the code adds the account to the hashtable and then it does the editing part by opening the acc manage form.
So, i tried to do this in my search form like this:
IAccount account = new Account(tmpName, "");<br />
doEditAccount(account);<br />
bank.AddAccount(account);<br />
this.Close();
Now the previous error is gone and have a new one:
The name 'bank' does not exist in the current context
The AdvSearchForm is VERY similar to the MainForm, yet how can the form cannot find the instance 'bank' ?
|
|
|
|
|
Latheesan wrote: The AdvSearchForm is VERY similar to the MainForm, yet how can the form cannot find the instance 'bank' ?
Because bank is a field on the MainForm, not the form you are working on.
The MainForm takes the bank as a parameter in the constructor and stored it in a field (sometimes known as a member variable). Perhaps you should do the same with this form.
|
|
|
|
|
Great, brilliant suggestion.
I added the following line towards the begining of the partial class:
IBank bank;
editted the search method like this:
IAccount account = new Account(tmpName, "");<br />
doEditAccount(account);<br />
bank.AddAccount(account)
And i was able to successfully build the solution.
However, when i use the search form and enter an account ID and click search, it opens the account management form correctly, but when i close the account management form, i get this exception error message:
http://i9.tinypic.com/4poqqab.png[^]
|
|
|
|
|
Nevermind, i fixed it by removing this line:
bank.AddAccount(account);
from the search method and it seems to be working.
I know this is terrible, trial-and-error method is not a good way to learn new programming language, but im short on time. Im just glad its working and i can move onto the next piece of work.
|
|
|
|
|
But you didn't pass a bank object to the form. Either do this in the constructor, or by setting up a property to receive it. The constructor option is usually preferable if it will always need it, or the object is mandatory.
|
|
|
|
|
But you didn't pass a bank object to the form.
I didn't need to, so i ended up removing the line IBank bank;
|
|
|
|
|
In addition to what colin said, I assume your IAccount instance probably has a property that you can access to pass the information you're wanting to pass where a string is expected.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Thanks allot sir for your reply, but im a bit confused by what you said, since i've never programmed before till few months ago, im still getting used to using Visual Studio C# Express software and learning C#
This is for my programming course (1st year) and it's alrady doing my head.
|
|
|
|
|
well, I'd recommend buying a book and working through it. We're glad to help ( you're asking us to help and trying to do it yourself, and that's never a problem ), but a trial and error approach isn't going to help you understand the core principles that you're struggling to grasp now. The main issues here as far as I can see:
1 - a variable has a type. If you try to pass an object of the wrong type, you're putting a square peg in a round hole. It's a 'thing', but it's not the right 'thing'.
2 - A class is an object designed to wrap specific functionalty. Once you define a class, you can have many instances of a class, just like knowing what a car is, I can own 3. If I have three cars, they are all independant objects, changing the tires on one car won't change the other ones. And, objects that exist within a class, are not visible outside that class, unless they are public, and then they need to be addressed via the class instance. If I want something that's in my car, I have to look inside the car, not on the ground.
I hope that makes *some* sort of sense, but seriously, read through the texts you've been given, or consider buying a book. And, do some really basic to the point of useless projects that exist entirely to help you understand concepts like types and class scope.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
I'm writing an Outlook Add-in using VSTO 2005. However there's a slight problem; when I attach event handlers to the CustomAction event of MailItems sometimes the function doesn't get called. There are cases when attaching them more times (at run-time) overcomes this problem, however sometimes it looks like they don't "stick", meaning I click a custom action button once and it works, then I push it a second time and now the handling function does not get called. I even fail to recognize the pattern in this random behavior.
Has anyone else faced similar issues, and if so how do I overcome them?
|
|
|
|
|
I recently did a combination plugin for Excel/Outlook using the Office 2007 PIAs and VSTO2005... I ran into the same behavior with BOTH applications... What I finally had to end up doing was after each event was fired, I rewired the event, just to be on the safe side because I could not predict when and where it would happen.
It's a nasty thing to have to do, but it's no worse than having to switch a 1-based index just to code to Office apps.
HTH,
~dnc
|
|
|
|
|
That I already tried - even so the the problem still remains
|
|
|
|
|
|
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); <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
|
|
|
|
|
hdv212 wrote: DataColumn dc3 = ds.Tables["t_sessions"].Columns["sessionID"];
DataColumn dc4 = ds.Tables["t_titles"].Columns["sessionID"];
Are you sure that each value in t_titles has a session Id that is found in t_sessions ?
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
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
|
|
|
|
|