|
Try this:
change the button1 to your update button name
dataSet21 to your DataSet name.
oleDbDataAdapter1 to your DataAdapter name.
Products to your table name.
I used Northwind database via MSDE and it worked.
private void button1_Click(object sender, System.EventArgs e)<br />
{<br />
if (dataSet21.HasChanges())<br />
{<br />
try<br />
{<br />
int nModified;<br />
nModified = oleDbDataAdapter1.Update(dataSet21.Products);<br />
string strOutput;<br />
strOutput = "Modified " + nModified + " products(s)";<br />
MessageBox.Show(strOutput, "Update succeeded!", <br />
MessageBoxButtons.OK, MessageBoxIcon.Information);<br />
}<br />
catch (Exception ex)<br />
{<br />
MessageBox.Show(ex.Message, "Update failed!",<br />
MessageBoxButtons.OK, MessageBoxIcon.Error);<br />
}<br />
}<br />
else<br />
{<br />
MessageBox.Show("No changes to submit!", "SubmitChanges",<br />
MessageBoxButtons.OK, MessageBoxIcon.Information);<br />
}<br />
}
Don't and drive.
|
|
|
|
|
I just want to make sure I'm on the same page as you ( I'm new to C# ). You added oleDbDataAdapter1 to the form and by adding this object studio creates your insert, update, and delete statements for you? The dataSet21 dataset is the same one you used to populate the grid in the first place? So just make the changes you mentioned and that's it?
Thanks for all your help!
|
|
|
|
|
Manster wrote:
I'm new to C#
Me too.
Manster wrote:
You added oleDbDataAdapter1 to the form and by adding this object studio creates your insert, update, and delete statements for you?
Yep. Using "Data Adapter Configuration Wizard" (by dragging
OleDbDataAdapter onto the form)
Manster wrote:
The dataSet21 dataset is the same one you used to populate the grid in the first place?
Yes. I generated the dataset via adapter properties, where I clicked the "Generate Dataset" or You can do via "Data" menu -> "Generate Dataset"
Select "New" and select your table.
Is that what you are looking for? or Am I mumbling something else?
Don't and drive.
|
|
|
|
|
Yea I think that's it. I declared a dataset object in my code, I didn't add it to the form through the generate option. Hopefully that will do the trick. I haven't had a chance to test it yet.
Thanks for all your help!
|
|
|
|
|
For some reason I can't get your changes to work. Is their any chance you can send me your demo project?
Thanks
|
|
|
|
|
I have a client who wants to upgrade their office to a windows environment, but they want it to be as similar as an old dos program they've been using since the year dot.
Because of this, I have to make a program that they can navigate entirely with the keyboard. Currently I am stuck trying to work out how to make the menus either get the focus (so they can use the arrow keys to navigate), or make a menu open just from a keypress. I have tried calling the MenuItem.Select or MenuItem.PerformClick method, but neither of these seems to bring the focus to the menu.
Does anyone have an idea where to look for this? - I have seen hundreds of articles on how to create a menu item when i searched, but none to simply open a menu.
|
|
|
|
|
1. In the menu item, define the Text with ampersand
ex: &File.
Then you can use the shortcut ALT+F to get to this menu
2. Look after accelerators in MSDN
|
|
|
|
|
Unfortunately that won't work for this program. Because of the way the dos program was structured I need to be able to press a single key (in this case the left or right arrow) to open the menu's. Most of the staff that use this program might be able to turn a computer on on a very good day and the owner doesn't want to have to retrain them (hah) to learn to use a new program.
What I am looking for is the equivalent of menu.open or menu.focus (as such), ie: how can I call the equivalent of a mouse click on a menu in code to make the menu open? MenuItem.PerformClick would work, if I knew how to tell the menu to open.
|
|
|
|
|
action at property window:
for windows form has an DataGrid with set to ReadOnly. Then, no more action to modify the ReadOnly value to false ("Invalid Property, Object reference not set to an instance of an object") ?!?!
but when u try to write code for perform below action, it's ok.
and another way: open code window, expand the node (region) "Windows Form Designer generated code" (M$ auto generated code for your visual interface), navigate to the DataGrid definition and simply set the ReadOnly property to false.
Is here any my mistake?
|
|
|
|
|
Can anyone replicate this or confirm it?
...
object[] arr = new object[]{"blah", "leppie", null};
object[] arr2 = new object[]{null, "leppie", null};
...
void Foo(Array arr)
{
}
Thanks
PS: this seems only to happen with boxed strings and not with other value types.
Hey leppie! Your "proof" seems brilliant and absurd at the same time. - Vikram Punathambekar 28 Apr '03
|
|
|
|
|
The same problem can be observed in Foo as such:
object[] arr2 = new object[]{null, "leppie", null};
...
void Foo(Array arr)
{
arr.SetValue("blah", 0);
}
Please someone give me a work around!
Hey leppie! Your "proof" seems brilliant and absurd at the same time. - Vikram Punathambekar 28 Apr '03
|
|
|
|
|
Unfortunately I cant do that This class serves for a base class that needs to take any array. I dont want to copy all the elements.
Anyways, its appears rather to be a VS.NET 2002 watch window bug, as testing for null and "", null comes up .
Hey leppie! Your "proof" seems brilliant and absurd at the same time. - Vikram Punathambekar 28 Apr '03
|
|
|
|
|
leppie wrote:
this seems only to happen with boxed strings and not with other value types.
Considering string isn't a value type, it isn't being boxed at all. But I still don't think you should see null being converted to "" for any reason. The two values can mean entirely different things, especially when dealing with a database (the difference between no value specified and an empty string specified).
James
"It is self repeating, of unknown pattern"
Data - Star Trek: The Next Generation
|
|
|
|
|
Thanks, it appears to be a VS.NET 2002 cosmetic bug rather. See above reply.
The reason why I am boxing everything is have a null value for all types so I can have "holes" in the array.
Also this I could for the life of me not to work:
Array chararrarr = Array(typeof(char[]), 2);
chararrarr.SetValue( "blah".ToCharArray, 0);
chararrarr.SetValue( "blep".ToCharArray, 1);
char[][] carar = (char[][]) chararrarr;
The only way I found is to copy the chars one by one
Hey leppie! Your "proof" seems brilliant and absurd at the same time. - Vikram Punathambekar 28 Apr '03
|
|
|
|
|
Arrays can only have one type of element.
So I think that "string1", "string2", null
is the proper behavior.
|
|
|
|
|
Bo Hunter wrote:
Arrays can only have one type of element.
Yes, and I want it to stay object, not string, but as said, it seems to be an IDE problem and not a language issue.
Hey leppie! Your "proof" seems brilliant and absurd at the same time. - Vikram Punathambekar 28 Apr '03
|
|
|
|
|
Is there a way to fire an event from a class, from outside that class? I mean, if i have something like the following, can ClassA fire ClassB's Click event?
public class ClassA
{
ClassB myB;
}
public class ClassB
{
public event EventHandler Click;
}
I tried
myB.BeginInvoke(myB.Click, new object[] {null, null}); but it didnt compile
Thanks
Adam
|
|
|
|
|
Adam Turner wrote:
Is there a way to fire an event in a class, from outside that class?
No, events can only be fired by the class that defines them. However, if you follow the recommended event pattern* then classes that inherit from ClassB could fire the event.
*The recommended patter is to define your event, MyEvent then also have a protected method called OnMyEvent(MyEventArgs e) . In the class defining the event, OnMyEvent just fires the event.
If a class inherits from the one defining the event then there are three purposes for the OnMyEvent method. First is to handle the MyEvent event, without needlessly attaching a delegate to the event.
The second purpose ties in with the first, by not calling base.OnMyEvent(e); in your derived class you can prevent the event from firing. This is useful if you wish to restrict the times when the event is fired.
The third purpose can be to fire the event from within the derived class, this one is trickier because ensure that you don't break any implied behavior concerned with the event firing. To fire it, just call OnMyEvent and pass in the appropriate EventArgs object.
Of course, an example
class TheBase
{
public event EventHandler MyEvent;
protected virtual void OnMyEvent(EventArgs e)
{
if( MyEvent != null )
{
MyEvent(this, e);
}
}
}
class TheDerived
{
protected override void OnMyEvent(EventArgs e)
{
if( ShouldFireMyEvent )
{
base.OnMyEvent(e);
}
else
{
}
}
public void FireMyEvent()
{
OnMyEvent(EventArgs.Empty);
}
} HTH,
James
"It is self repeating, of unknown pattern"
Data - Star Trek: The Next Generation
|
|
|
|
|
Hi All,
I was reading in the MS preparation guid for exam 70-316 that I can host any Windows Forms control in IE by using the following code
<object id="MyControl"
classid="http:ControlLibrary1.dll#ControlLibrary1.myControl"
viewastext="">
but when I tried it, it didn't work.
|
|
|
|
|
|
Hi,
I'm new of this site/forum so first of all I wanna say hello to everyone.
Then, I'm trying to develop an addin for visual studio .net but I'm having some problems due to my inexperience in c#.
What does it mean when I write:
EnvDTE.Window thisWindow = x.open(...);
Does it mean that I'm considering the current tab (the tab the user is working on) or does it mean
that it's going to create a new tab under visual studio project ??
I'd like to code something similart to the first solution...
Then I have some problems also to browse the documentation: where is the namespace EnvDTE?? I can't find it ...
thanks
|
|
|
|
|
cbiacca wrote:
I'm trying to develop an addin for visual studio .net
Sudden interest for VS.NET addins, or could it be that...;)
cbiacca wrote:
EnvDTE.Window thisWindow = x.open(...);
The best way to develop an add-in is to use a top-down design. I would recommend to use one of the wizards available when you create a new project (Extensibility projects / VisualStudio .NET add-in), which provides all the underlying code to start with.
Of course, the object model is documented. A chart is available here[^]. And the doc is here[^].
cbiacca wrote:
where is the namespace EnvDTE??
Although the add-in wizard adds the reference to it, you can add it manually to your project by adding a reference to this file : C:\WINNT\Microsoft.NET\Framework\<version>\EnvDTE.dll (C# using EnvDTE; )
Don't forget to add a reference to this assembly as well : <VS.NET install dir>\Common7\IDE\PublicAssemblies\Extensibility.dll (C# using Extensibility; )
|
|
|
|
|
First I wanna thank you to have answered me ... The reason I'm trying to develop an addin was that visual studio .net doesn't allow to highlight the braces. I'm used to develop in java where all RAD have this feature.
Anyway I had already used the wizard to get started to develop ing this addin so I had all the reference I need (I hope so :P).
Because I haven't a clear idea about how it really works, I thought I had to select the tab on what the addin should works, so I used the code:
EnvDTE.Window thisWindow = x.open(...);
Now that you gave me the documentantion's link, I'm gonna try to understand a little bit more.
In the end, regard to the questione "where is the namespace EnvDTE", now I understood not to have been clear. I meant where it is in the documentation. Actually I'd like to know what classes it includes, but I can't find it ... i.e.: I mean, is it under System. ?
I know by the code which was created by the wizard that I have to use EnvDTE so I supposed it is an apart namespace but I can't really find it ...
Maybe, because of my bad english, I can't explain my question very well, if so don't worry I'm gonna work using tips you gave me ...
Thanks
|
|
|
|
|
cbiacca wrote:
In the end, regard to the questione "where is the namespace EnvDTE", now I understood not to have been clear. I meant where it is in the documentation
One of the links I have provided is the root of the EnvDTE namespace.
cbiacca wrote:
Actually I'd like to know what classes it includes, but I can't find it
Add a reference to it in your project workspace, then add "using EnvDTE;" in your code, then you can use intellisense to see all classes...
cbiacca wrote:
I mean, is it under System. ?
Namespaces with names of the form System.xxx are "primary" assemblies. In fact, the .NET run-time is made of a collection those assemblies, plus a few things.
The assemblies related to the VS.NET IDE (EnvDTE and Extensibility for the two main you are likely to deal with) are not part of the .NET run-time. MS could have decided to name them System.EnvDTE.EnvDTE, System.EnvDTE.Extensibility, ... but they chose not to. Other than that, these are assemblies and you can use any assembly explorer to dive into the classes/methods/... (you can use the VS.NET IDE Object Browser window for instance).
|
|
|
|
|
cbiacca wrote:
The reason I'm trying to develop an addin was that visual studio .net doesn't allow to highlight the braces
It's because the CodeProject competition this month is about the best add-in that someone would submit.
|
|
|
|