|
Hi
I am working on a desktop application using C# n .NET 2.0. I have a BindingNavigator, BindingSource and a DataSet on a screen. Their properties are set as follows.
BindingNavigator1.BindingSource = BindingSource1;
BindingSource1.DataSource = DataSet1;
BindingSource1.DataMember1 = DataSet1.Table1;
Now the AddNewItem event of BindingNavigator looks something like and here is what I want to do.
void BindingNavigator1_AddNewItem_Click( sender s, EventArgs e )
{
// if( MyCond )
// Cancel this event;
// else
// Go Ahead;
}
I think there should have been e.cancle(); to cancel this event but it is not there. So I cannot find out how to cancel this event. Can anybody help me out?
|
|
|
|
|
This might help you
void BindingNavigator1_AddNewItem_Click( sender s, EventArgs e )
{
if( MyCond ) {
// delete the coming item
BindingNavigator1.BindingSource.CancelEdit();
} else{
// go ahead..
}
}
//C0ax
If it' stuck, DO NOT pull harder!
|
|
|
|
|
Thank you so much. It was really helpful. Thankx once again
|
|
|
|
|
Well the situation has become a bit complex. In my DataSet I have two tables say table1 and table2. They have one to many relation (no rule is set like for update, delete or accepct/reject changes). When I drop a binding source for the parent table i.e table1, I get another binding source for child i.e table2BindingSource1 after rebuilding the project. That is really helpful because when I set
//this.BindingNavigator1.BindingSource = table1BindingSource;
The self created BindingSource collaborates with the navigator itself and I need not to do any extra coding.
Now the problem is when I do
//this.BindingNavigator1.BindingSource.CancelEdit();
to cancel any changes made to DataSet in case user clicks Delete button one the Navigator.
This only works for the parent table i.e table1 and not for the child table or say for self created BindingSource.
How can I apply this CancelEdit for both the tables in the DataSet ( for both BindingSources ).
Can anybody help me out?
|
|
|
|
|
I have a table in MS SQL Server database like this;
ID int PK
User_ID int
Discussion_ID int
Message text
Date datetime
I want to execute this query in my source code;
DateTime currentTime = System.DateTime.Now;
sql = "INSERT INTO TBL_POSTS(User_ID, Discussion_ID, Message, Date) VALUES('";
sql += User.Identity.Name + "','";
sql += discussionId + "','";
sql += message + "','";
sql += "#" + currentTime + "#')";
cmd.CommandText = sql;
cmd.ExecuteNonQuery();
ERROR: Conversion failed when converting datetime from character string.
How can I add DateTime field to databse.
|
|
|
|
|
I am not sure where the # comes from, that's not correct syntax ?
Is message in some way parsed to stop people using your form from using an injection attack to erase your database ?
your best option is to use a parameterised query or stored proc, and just passng the date through as a date.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillionOneHundredAndFortySevenMillionFourHundredAndEightyThreeThousandSixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it )
|
|
|
|
|
Christian Graus wrote: I am not sure where the # comes from, that's not correct syntax ?
That's the syntax used with an MS Access database.
---
"Anything that is in the world when you're born is normal and ordinary and is just a natural part of the way the world works. Anything that's invented between when you're fifteen and thirty-five is new and exciting and revolutionary and you can probably get a career in it. Anything invented after you're thirty-five is against the natural order of things."
-- Douglas Adams
|
|
|
|
|
dataminers wrote: sql += message + "','";
sql += "#" + currentTime + "#')";
SQL Injection Attack Heaven... There are hackers out there who are just wetting themselves in anticipation of that code to going live so they can compromise your system.
Tips on how to prevent SQL Injection Attack[^] - And it will solve your data conversion problem too!
|
|
|
|
|
An Access database uses # around a date literal, MS SQL uses apostrophes. No database (to my knowledge) uses both.
For an Access database, the correct syntax would be:
...<br />
sql += message + "',#";<br />
sql += currentTime + "#)";
For an MS SQL database, the correct syntax is:
...<br />
sql += message + "','";<br />
sql += currentTime + "')";
However, I fully agree with the other posters that you should use a parameterised query. It both solves problem with date formats and the problem with SQL injection vonurability that you get when putting the values in the query without encoding them properly.
---
"Anything that is in the world when you're born is normal and ordinary and is just a natural part of the way the world works. Anything that's invented between when you're fifteen and thirty-five is new and exciting and revolutionary and you can probably get a career in it. Anything invented after you're thirty-five is against the natural order of things."
-- Douglas Adams
|
|
|
|
|
how do i get data from the database
-- modified at 5:28 Wednesday 24th October, 2007
alok2171
|
|
|
|
|
alok2171 wrote: how do i get data from the database into the drop down box.
Use ADO.NET[^].
Also consider reading rule 2 of the forum guidelines.
Paul Marfleet
|
|
|
|
|
hi friends i am using property grid in my programming and there is no event for the background image change actually i need to store the path of the image as there is no event so its creating a problem
if anyone knows this plz tell me
regards
sindhu tiwari
its me sid
|
|
|
|
|
No event, or no property ?
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillionOneHundredAndFortySevenMillionFourHundredAndEightyThreeThousandSixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it )
|
|
|
|
|
sir there is a property but no event associated with it ..
my aim is to store the address of the image file when the background image is changed.
if u have any idea abt how to find the image address(physical path) of a picture
box's background image which is added dynamically using a property grid not by a
openfile dialog
plz tell me
its me sid
|
|
|
|
|
OK, then create a class that derives from this control, override the property, and add an event.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillionOneHundredAndFortySevenMillionFourHundredAndEightyThreeThousandSixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it )
|
|
|
|
|
Hi,
I have created window application, now I want to use that window application in my Web application. So how it possible ?
I have get idea that I have to add tag in WebPage named as Object. In that I can assign that window application.
Any idea ??
Thanks,
Sun Rays
|
|
|
|
|
You can embedd a control in your web site, but it means your clients need to download your code and have .NET installed. There's info on MSDN, but I don't know of many people who do it.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillionOneHundredAndFortySevenMillionFourHundredAndEightyThreeThousandSixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it )
|
|
|
|
|
I've tried this once, there are *lots* of security issues you'd have to resolve on each client, depending on what the applications does - network, IO ,alotothersstuff...
if you just want to start the app from the browser look at clickonce deployment. clickclick done
If it' stuck, DO NOT pull harder!
|
|
|
|
|
Of course you could just write another UI layer for the web for your application, because of course all your business logic is separated out of the presentation layer....
|
|
|
|
|
hi,
i have two textboxes form1 and form2
in form1 and form2 i have two textboxes....
what ever i enter in textbox in form2 should be updated into textbox in form2...
i dont want to use delegates....
i have an idea ie....whatever is in textbox in form2 has to be called in form1...for that i need to create an object...but where and how and how to make it display....
can anybody give me the structure of the code in both the forms so taht i can try with that.......
thanking you
C#
|
|
|
|
|
|
kabutar wrote: i dont want to use delegates....
Why not ? Delegates are the best way to do this, why are you setting out to write bad code ?
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillionOneHundredAndFortySevenMillionFourHundredAndEightyThreeThousandSixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it )
|
|
|
|
|
yes Christian i understand that but i want to try it this way also.....
just for once so that i know how exactly it works.....
just curious may be......
thanks in advance for your repeated help...
C#
|
|
|
|
|
Is the form1 parent of form2 ?
Koushik
|
|
|
|
|
yes Koushik .....
form1 is the parent form and form2 is the child form....
when we click on a button in form1 the form2 will pop up.....
thanks in advance...
C#
|
|
|
|