|
considering that i only used oleDbAdapter and generated select command, i run my app and query for data from Access db. i then make some changes to the data that are retrieved and displayed in my dataGrid, and i press the update button.
update button:
private void button3_Click(object sender, System.EventArgs e)
{
try
{
oleDbDataAdapter1.Update(dataSet51); MessageBox.Show("Database Updated");
}
catch (Exception exceptionObject)
{
MessageBox.Show(exceptionObject.Message);
}
}
error message:
Update requires a valid UpdateCommand when passed DataRow collection with modified rows
well i suppose the reason is because i failed to generate the update command using oleDbDataAdapter right??
in that case, what do i do? i do not know how to use a commandbuilder.
can you please tell me what to do? thank you! =)
|
|
|
|
|
i think i should tell you this:
i learnt that a missing primary key in my db table might be the cause for my failure to generate the UpdateCommand. i'll be using table2's data to generate the UpdateCommand.
hence i tried to add a pk, but i could not save my changes. (error is something like this: saving will cause duplicate pk)
well, i suppose it's because i already had a pk (IDno )in table1, and what i was trying to do was to let IDno in table2 be pk as well.
in the end, i have only one pk (IDno in table1). i meant to let IDno be pk in all of my tables... is this possible??
one thing to note: i used oleDbDataAdapter to generate commands using table1 and all the commands were successfully generated. i think i succeeded because i've a pk in table1, am i right??
hope that's helpful for you to understand my problem..
please help me... i donno how i should rectify the problem (to make an UpdateCommand for table2 and be able to update back to Access db).
thanks for reading.
|
|
|
|
|
send me an email for recieving a free sample in c#.net database .
my email:nmm705@yahoo.com
Mostafa
|
|
|
|
|
Hi all,
here's a question for you.
What if one needs to do automatic disposing of a form's components when it is closed ?
And what if one wan't write Dispose() for each component ?
Here is my answer, I hope you agree is correct. I tested it in win2k/winXp with taskmanager and I have seen this piece of code effectively release the memory when the form is closed.
Suggestions are really appreciated.
public static void disposeComponents(Component f) {
foreach (FieldInfo fieldInfo in f.GetType().GetFields(BindingFlags.Instance | BindingFlags.NonPublic)) {
object value = fieldInfo.GetValue(f);
if(value is Component) {
((Component)value).Dispose();
fieldInfo.SetValue(f, null);
}
}
System.GC.Collect();
}
|
|
|
|
|
zu78 wrote:
System.GC.Collect();
Read this[^]. In a nutshell, if you don't trust the Garbage Collector, use C++ instead ( my words, not his ).
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
I will read that (I' quite new to C#), but I don't like C++
|
|
|
|
|
Second version:
public static void disposeComponents(Component f, bool disposeForms) {<br />
foreach (FieldInfo fieldInfo in f.GetType().GetFields(BindingFlags.Instance | BindingFlags.NonPublic)) {<br />
object value = fieldInfo.GetValue(f);<br />
if(value is Form && disposeForms == false) continue;<br />
if(value is Form && f is Form) {<br />
if( ((Form)f).ParentForm == value ) continue;<br />
if( ((Form)f).MdiParent == value ) continue;<br />
}<br />
if(value is IDisposable && value != null) {<br />
((IDisposable)value).Dispose();<br />
fieldInfo.SetValue(f, null);<br />
}<br />
}<br />
System.GC.Collect();<br />
}
|
|
|
|
|
I reiterate - if you don't trust the garbage collector, don't use it. You're fighting the framework, and performance can only suffer.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Forget the garbage collector (comment that line).
I've posted that snippet to share with the community this idiom of disposing components in C# Windows Forms applications.
Hope this clarify the topic of this post.
Thanks however for the suggestion (as I have already said, I am new to C#)
|
|
|
|
|
Using Visual Studio .NET 2003, how do I give a .exe an icon? I know, with vb .net just click properties on the project then go to ==> build ==> application icon.
Thanks
|
|
|
|
|
In the yourForm class
this.Icon = //your icon
|
|
|
|
|
I actually want an icon for the executable file not just in the form's title bar.
Thanks for the reply!
|
|
|
|
|
|
It was under properties --> common properties --> general -->application.icon for my C# project. I simply overlooked it. Thanks for your reply!
|
|
|
|
|
Could someone post a few lines of code using Regex to validate data in a text box?
My requirements are to A)ensure that the text entered is a number that can be positive or negative and B)it can either have a decimal point or not have a decimal point. That's it....
Anything that could get me started learning Regex would be appreciated....
I've read several articles today but can't seem to find one to address this particular type of problem, that is-- I know how to validate "abc" but not an integer or floating point.
|
|
|
|
|
Expresso is the program you need to learn regex.
How about -?\d+.?\d? ? This DOES require a leading digit on the decimal place tho. Making this optional but making sure there's more than just a . and no numbers is a little more complex.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
|
Using the Word Object in C# I have implemented the before save event. I set the cancel boolen to true but it still does not cancel the save. I am programming in office xp using word 10.0 dll. anybody have any idea what I am doing wrong?
public void myWordApp_DocumentBeforeSave(Microsoft.Office.Interop.Word.Document doc, ref bool SaveUI,ref bool Cancel)
{
if (GetProperty(doc))
{
Process[] procs = Process.GetProcessesByName("WINWORD");
IntPtr hwnd = procs[0].MainWindowHandle;
DialogResult result =
MessageBox.Show(new WindowWrapper(hwnd),"Do you
want to quit save
action?","OfficeTest",MessageBoxButtons.YesNo);
switch (result)
{
case DialogResult.Yes:
Cancel = true;
break;
default:
break;
//save it.
}
}
}
Thanks
notsnoj
|
|
|
|
|
found my solution on the below web page
http://support.microsoft.com/default.aspx?scid=kb;en-us;830519
notsnoj
|
|
|
|
|
Using the Word Object in C# I have implemented the before save event. I set the cancel boolen to true but it still does not cancel the save. I am programming in office xp using word 10.0 dll. anybody have any idea what I am doing wrong?
public void myWordApp_DocumentBeforeSave(Microsoft.Office.Interop.Word.Document doc, ref bool SaveUI,ref bool Cancel)
{
if (GetProperty(doc))
{
Process[] procs = Process.GetProcessesByName("WINWORD");
IntPtr hwnd = procs[0].MainWindowHandle;
DialogResult result =
MessageBox.Show(new WindowWrapper(hwnd),"Do you
want to quit save
action?","OfficeTest",MessageBoxButtons.YesNo);
switch (result)
{
case DialogResult.Yes:
Cancel = true;
break;
default:
break;
//save it.
}
}
}
Thanks
notsnoj
|
|
|
|
|
I'm a student currently trying to learn C# for software engineering class. I've got a question about C# classes. In vb all you have is public class "class" and then end class. However, in C# you have:
public class Contact
{
public Contact()
{
}
}
What is the purpose of public Contact() within public class Contact?
Thanks!
|
|
|
|
|
|
VB must have constructors, you just may not have seen them. As your code stands, you could remove the second public Contact, as it does nothing. However, this code is called automatically when you create a new Contact, and so you can put any variable initialisation or other actions you may have to take to set up a Contact within this class.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
VB have Constructor too but unlike C# where the constructor name is the class name the VB constructor name
is New So your VB class will be somthing like
Public Class Contact
' Class Constructor
Overloads Sub New( )
End Sub
End Class
MCAD
|
|
|
|
|
You can have many constructors as well but they must all differ in their parameters. This allows you to create your Contact class differently depending on what parameters you pass it, which means only one of the constructors will be called when you instantiate (create) your Contact object. I think this is what they mean by the term "polymorphism".
public Contact()
{
}
public Contact(int publicID)
{
}
public Contact(int publicID, int securityID)
{
}
notsnoj
|
|
|
|