|
I know i can easily delete all records with "delete from biler" and i know the problem is not related to my SQL-statements or db schema. I'm just new to working with the DataSet. Since i want to learn how to work with the dataset i want to avoid using the method above. I want to be able to remove records one by one in the future...
The table has a primary key defined in my Access db, however it seems that the DataAdapter doesn't retrieve any meta data about primary keys and constraints from the table( as stated in msdn ). That's probably way the message says that i don't have a primary key. MSDN also states that i should specify which column is the key column somewhere in code and i have read something about MissingSchemaAction.AddWithKey ...
The problem is that i can't seem to get it right. How do i make the DataAdapter fetch information about the primary key? Or how do i tell the DataAdapter that a certain column in the fetched table is actually a primary key column? This is really bugging me out
-- modified at 4:59 Friday 23rd December, 2005
|
|
|
|
|
There's go to be something wrong with your table then. There's no problem with using a DataAdapter with an Access table.
If your table is correct, then you really don't have a need to specify which column is the PK. I've never run into the problem. This code works just fine:
[EDIT]Sorry, wrong language for the forum...[/EDIT]
string connString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\\TestBlank.mdb";
string sql = "SELECT * From MyTable";
OleDbDataAdapter da = new OleDbDataAdapter(sql, connString);
OleDbCommandBuilder cb = new OleDbCommandBuilder(da);
DataSet ds = new DataSet();
da.Fill(ds, "MyTable");
foreach (DataRow row in ds.Tables("MyTable").Rows)
{
Debug.WriteLine("ID: " + row("TestID"));
row.Delete();
}
da.DeleteCommand = cb.GetDeleteCommand();
da.Update(ds, "MyTable");
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
-- modified at 10:25 Friday 23rd December, 2005
|
|
|
|
|
I tried changing primary key data type from "PM" to "Text" in the db and now it works just fine. I really did have a primary key though , and after reading that thing about "...OleDbDataAdapter not fetching primary key constraints..." on MSDN i really thought i was in trouble.
But as always, the problem lies in something small and unsignificant to the eye
Dave Kreskowiak wrote: [EDIT]Sorry, wrong language for the forum...[/EDIT]
I'm pretty fluent in VB syntax so i don't mind
Thanks a lot for the help!
|
|
|
|
|
Stefan R wrote: I'm pretty fluent in VB syntax so i don't mind
Yeah, I changed the code becauseif you're caught posting VB code in the C# Forum, ... well, let's just say it makes the movie "Desparado" look like a Sunday Brunch.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
if i create a webbrowser object, and there is a form (with name="something") on the page displayed, is there a way i can automatically submit it using c#?
thanks in advance,
sam kline
<a href="http://dying.about.com/gi/pages/poll.htm?poll_id=2068629450">YES</a>
|
|
|
|
|
Hi, Does anyone know a good way to make reports in c#? not in Crystal Reports(Money issue) ..
i'm lookin for a simple report, maybe something thats like access reports.. ..
any idea will do ..
thanks in advance ,.. Yosi.
|
|
|
|
|
There is at least one free library that draws graphs, you could use that to create your own report, I guess. You'd have the data you need from your data source already.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
I recently made reports using the GDI, PrintDocument and PrintPreview controls of .NET. Although its a lot of boring work when you use GDI to draw lines and such but I did it.
Bikash Rai
|
|
|
|
|
Is there anychance you can post me the code?
i'm in a mess... i got this presentation on sunday, and i was counting on that crystal reports, but then i found out it need to be registerd...
anyhow,, if you could post me the code , i will the most grateful man on eatrh!
|
|
|
|
|
I have sent you the code as a Zip attachment. Although the code is in VB.NET I think you won;t have any problems porting it to C#. I couldn't post the code here because the code's long...... really long.....
Happy Printing...
---
With best regards,
A Manchester United Fan
The Genius of a true fool is that he can mess up a foolproof plan!
|
|
|
|
|
http://www.codeproject.com/csharp/letaonarticle2.asp
|
|
|
|
|
The code are looks like this:
Panel panel1 = new Panel();
if(panel1.CanFocus){
panel1.Focus();
}
Then it generated a exception at the run-time.
An unhandled exception of type 'System.InvalidOperationException' occurred in mscorlib.dll
Additional information: Collection was modified; enumeration operation may not execute.
Focus() has nothing to do with the collection, is that because of UIPermission fails?
Thanks
|
|
|
|
|
Perhaps a handle of panel1 fires a method that generates that exception or that prepare the field for the exception.
protected internal static readonly ... and I wish the list could continue ...
|
|
|
|
|
You're getting this error because a Panel control cannot receive the input focus. See Control.Focus()[^] for a list of controls that cannot be .Focus ed.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Thanks a lot. I will try to not use focus() in my code.
In fact, my problem is as this:
if(A.Focused){
B.Focus();
A.Focus(); //get an exception in main()
}
The reason for reset A's focus is that I want to clear A's keyboard input buffer. Otherwise the A's keyboard input will always be put into the next selected item.
I guess it is a bug in .net library and it can not be fixed without the source code.
Thanks again.
Merry Christmas to everybody
|
|
|
|
|
This won't clear the keyboard buffer. Once the keystrokes are sent the that window, that's it. That window has to process them.
BTW: This is NOT a bug in the .NET Framework. This is the documented behavior of the control! The bug is in the design of your code.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Hi, someone knows what kind of component/widget/technique is needed to emulate the MSN (7.5) Options window behavior?
I mean, when you click any option in the listBox on the left, the groupBox of the right changes accordingly (with different set of options for each selected item).
I want to do a Configuration dialog like that and it seems not so obvious for me to figure out the best or smart way to do that.
Thanks in advance
Zopiro
|
|
|
|
|
How to break long line of code into several lines of short codes like what one can do in C++?
Thanks!
Devin
|
|
|
|
|
int my_very_long_variable_name = My_Very_Long_Method_Name(my_first_argument, my_second_argument, my_third_and_longest_argument, "some very long long string....");
Can be writen as well as
int my_very_long_variable_name = My_Very_Long_Method_Name(
my_first_argument,
my_second_argument,
my_third_and_longest_argument,
"some very long"+
" long string...."
);
btw, if you have a very long math expession, uualy is more useful to write it step by step (aoiding bugs is a must)
protected internal static readonly ... and I wish the list could continue ...
|
|
|
|
|
|
<br />
int i;<br />
Form2 f2=new Form2();<br />
<br />
private void button1_Click(object sender, System.EventArgs e)<br />
{<br />
f2.Show();<br />
f2.textBox1.Text=i.ToString();<br />
loop();<br />
}<br />
private void loop()<br />
{<br />
for(i=1; i<1000000;i++)<br />
{<br />
f2.textBox1.Text=i.ToString();<br />
f2.Refresh();<br />
}<br />
<br />
}<br />
<br />
<br />
<br />
With above code, I want to let i show in the testbox1 of form2 while the interation in funcion loop in going on. When I run the program. at first it works, but after i get to around 10000, the form2 freezs,and it will not update the value of i. If I click the form. The form2 's text will show some thing like ( not responding).
How can I fix this problem?
Thank.
|
|
|
|
|
Threads would solve your problems. Create the second form on a separate thread (and paint it - set the text property to aother controls) and all things should run smoothly.
protected internal static readonly ... and I wish the list could continue ...
|
|
|
|
|
Thank you for your response.
I have never program in thread. can you please give me an example or a source online where i can find an example?
Thanks
|
|
|
|
|
Search on CodeProject an example of SplashScreen (they are kind o the same, use threads in order to display dinmicaly changing data)
Implementing with threads your solution may not be the best method, but from what I can imagine this may work fine. If you want me to help you more specify in what circumstances you show the second form, and how long (until a button is pressed, or until a time is elapsed)
protected internal static readonly ... and I wish the list could continue ...
|
|
|
|
|
Here's some code. No comments, though. I'm sick today and don't feel that loquacious. Hope it helps.
using System;
using System.Threading;
using System.Windows.Forms;
namespace Project1
{
public class MainForm : Form
{
private OtherForm otherForm;
public MainForm()
{
otherForm = new OtherForm();
Button b = new Button();
b.Text = "Click Me";
b.Click += new EventHandler( RunAThread );
Controls.Add( b );
}
private void RunAThread( object sender, EventArgs ea )
{
otherForm.Show();
ThreadWorker tw = new ThreadWorker( otherForm.tb, new OtherForm.UpdateText( otherForm.UpdateTextBoxText ) );
Thread t = new Thread( new ThreadStart( tw.RunAlotOfIterations ) );
t.IsBackground = true;
t.Start();
}
[STAThread]
public static void Main( string[] args )
{
Application.Run( new MainForm() );
}
}
public class OtherForm : Form
{
public TextBox tb;
public OtherForm()
{
tb = new TextBox();
tb.Dock = DockStyle.Fill;
Controls.Add( tb );
}
public delegate void UpdateText( string text );
public void UpdateTextBoxText( string text )
{
Controls[ 0 ].Text = text;
}
}
public class ThreadWorker
{
private Control c;
private OtherForm.UpdateText ut;
public ThreadWorker( Control target, OtherForm.UpdateText del )
{
c = target;
ut = del;
}
public void RunAlotOfIterations()
{
for( int i = 1; i < 1000000; i++ )
{
c.Invoke( ut, new object[] { i.ToString() } );
}
}
}
}
"we must lose precision to make significant statements about complex systems."
-deKorvin on uncertainty
|
|
|
|