|
Good Day Blubbo
Your Textbox has an event "Textchanged" use it, it does exactly what you want.
Hope it helps.
Vuyiswa Maseko,
Few companies that installed computers to reduce the employment of clerks have realized their expectations.... They now need more and more expensive clerks even though they call them "Developers" or "Programmers."
C#/VB.NET/ASP.NET/SQL7/2000/2005/2008
http://www.vuyiswamaseko.somee.com
http://www.vuyiswamaseko.tiyaneProperties.co.za
vuyiswa@its.co.za
http://www.itsabacus.co.za/itsabacus/
|
|
|
|
|
to clarify this... I know how to handle the event by textbox.texthchanged. However, that in class 'b', "string" object is only being processed. So when the string value in class "b" is changed, the class "a" would see that string value in class 'b' is changed, the value in textbox is updated.
|
|
|
|
|
Now that means you have create the events in a class level. The way we approach the design of our application in our Project initial state can lead to this requirement. I think there is a part of your system that was poorly designed. but the workaround this is to create an event and if the value of class changes and you can change the text property of your textbox.
Hope this Helps
Vuyiswa Maseko,
Few companies that installed computers to reduce the employment of clerks have realized their expectations.... They now need more and more expensive clerks even though they call them "Developers" or "Programmers."
C#/VB.NET/ASP.NET/SQL7/2000/2005/2008
http://www.vuyiswamaseko.somee.com
http://www.vuyiswamaseko.tiyaneProperties.co.za
vuyiswa@its.co.za
http://www.itsabacus.co.za/itsabacus/
|
|
|
|
|
I think he's going the other way... Updating the textbox when the string changes.
There are plenty of ways to do this, and people will vehemently disagree on which is best, but here's one possible method:
1) Have your class implement the System.ComponentModel.INotifyPropertyChanged interface, and add the PropertyChanged event as specified in the interface
2) Add a wrapper for it, just to keep things clean:
private void OnPropertyChanged(string propName)
{
if (PropertyChanged != null)
PropertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(propName));
}
3) Instead of having the string just be a variable, change it into a property, like so:
private string _myStringValue;
public string MyProperty
{
get { return _myStringValue; }
set { _myStringValue = value; PropertyChanged("MyProperty"); }
}
Then you just listen to the PropertyChanged event, and update the textbox when "MyProperty" comes through.
|
|
|
|
|
so that "PropertyChanged" idea would be placed in which class? (class 'a' or class 'b') as explained in my recent post.
|
|
|
|
|
Class 'b'... The one that contains the string you're monitoring.
|
|
|
|
|
I think I've got this idea...
in class 'a':
Control: TextBox tbText
global:
BillAudit ba = new BillAudit();
constructor:
ba.DisplayOutput= tbText.Text;
in class 'b':
global variable: ReadWriteMessage (this is the string that class 'a' is watching)
public string DisplayOutput
{
get { return ReadWriteMessage; }
set { ReadWriteMessage = value; }
}
get the idea? might work?
modified on Tuesday, July 28, 2009 10:52 AM
|
|
|
|
|
That will set the DisplayOutput value to the textbox text... I thought you wanted it the other way around.
Like I said, implement INotifyPropertyChanged in class 'b', modify the set{} section for DisplayOutput to trigger a PropertyChanged event... Then in class 'a', you can do something like:
ba.PropertyChanged += new PropertyChangedEventHandler(...)
And in the event handler, you just do: tbText.Text = ba.DisplayOutput
Basically, the control flow goes like this:
1) ba.DisplayOutput changes
2) ba.DisplayOutput updates ReadWriteMessage
3) ba.DisplayOutput triggers PropertyChanged
4) Class 'a' sees the PropertyChanged
5) Class 'a' sets tbText.Text to the new value of DisplayOutput
|
|
|
|
|
|
Doesn't work why?
Do you have an exception? An error message from the database? Does the user you've connected to the database as have insert permissions? Is your query string correctly formatted? Is your getconnection() method returning an object correctly? Is there a specific line where the error occurs?
It definitely isn't definatley
|
|
|
|
|
not exception is caught
insert query is
String query = "insert into mydb values('" + textBox1.Text + "','" + textBox2.Text + "')";
This code was posted by me...
|
|
|
|
|
I notice you're using a try block, but I don't see the catch... Are you sure you're not just throwing away the exception?
And if there's really no exception, try setting a breakpoint and seeing exactly what "query" is being set to after that line runs. Maybe your textboxes are blank.
If the query is right, and you're really getting no exception, then it might be a database issue... Try running the exact query (Copy-paste it, so you know it's the same) in an SQL client to see what happens.
EDIT: Oops, responded to the wrong identical reply...
|
|
|
|
|
SqlConnection con = connection();
SqlCommand cmd = new SqlCommand();
cmd.CommandText = query;
cmd.Connection = con;
try
{
con.Open();
cmd.ExecuteNonQuery();
return 1;
}
catch (Exception e)
{
return 0;
}
finally
{
con.Close();
cmd.Dispose();
}
tis is the code its running fine without exception but no data is inserted into the table at last
This code was posted by me...
|
|
|
|
|
Obviously there is no exception that what a try catch does, it enables you to handle the exception, you catch is returning 0 so your not going to see any problem. You may have a problem with your insert statement too, have your tried specifying the columns you are trying to add data to?
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
yes i tried specifying the columns
but no use
any prob with insert query?????
String query = "insert into mydb(username,password) values('" + textBox1.Text + "','" + textBox2.Text + "')";
This code was posted by me...
|
|
|
|
|
try...
INSERT INTO mydb ([username],[password]) VALUES ('" + textBox1.Text + "','" + textBox2.Text + "')
Also...
- Confirm that 'mydb' is a table name and not the name of your database.
- make sure your database columns have the corrent datatype
- look into using parameters
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
What values does this method return? You're catching the exception but not doing anything with it (apart from changing the return value). Assuming you're using VS, set a breakpoint on the line "return 0;" and check to see that the value of 'e' (the exception) is.
It definitely isn't definatley
|
|
|
|
|
i debuggged the code
but no exception is caught
may be prob with insert statemnt???
any prob with insert query?????
String query = "insert into mydb(username,password) values('" + textBox1.Text + "','" + textBox2.Text + "')";
This code was posted by me...
|
|
|
|
|
Try changing your code to this:
SqlConnection con = connection();
SqlCommand cmd = new SqlCommand();
cmd.CommandText = query;
cmd.Connection = con;
con.Open();
cmd.ExecuteNonQuery();
con.Close();
cmd.Dispose();
and see if you get an exception - if the insert has failed, the database should indicate this.
It definitely isn't definatley
|
|
|
|
|
With regards to the query, I meant the actual string value that is being passed to the database, rather than the statement you use to construct it. Incidentally, is 'mydb' the name of the table or the name of a database containing the table (i.e. should it actually be "insert into mydb.dbo.mytable..."?).
What about the rest of the questions I asked? Have you tried running a profiler on the database to see if the query is actually received. Does the c# statement actually exectute?
It definitely isn't definatley
|
|
|
|
|
no exception is caught
i don knwo where is the problem
what is the meaning of this
"Have you tried running a profiler on the database to see if the query is actually received. "
This code was posted by me...
|
|
|
|
|
A database profiler is a tool which monitors a database and reports back when certain events occur, such as connections to the database, queries, triggers etc. SQL Server comes with its own profiler called (originally enough) SQL Server Profiler - I don't tend to use other databases but I'm sure there are similar tools available for other platforms.
It definitely isn't definatley
|
|
|
|
|
do we use cmd.ExecuteNonQuery()
for inserting??
This code was posted by me...
|
|
|
|
|
Yes that's fine. Broadly speaking, you use ExecuteNonQuery() to execute a SQL statement that doesn't return a result set, ExecuteQuery() to execute a statement that returns tabular data and ExecuteScalar() to execute a query which returns a single value (i.e. if you've done a count(*) or other scalar operation).
It definitely isn't definatley
|
|
|
|
|
If you want a meaningful response, you're going to have to be a lot more specific.
What exception are you getting? What line is triggering it? What query are you sending?
We're programmers, not psychics.
|
|
|
|