|
I trying to interact with a Microsoft Access Database in an application. Interactions include creating, deleting, and editing entries.
In Visual C# Studio, I have created a connection to the database, but I can't figure out what to do from there. Is there a way to cycle through the rows and columns in a database table using a for or foreach loop? I'm thinking it has something to do with the DataSet and other associated classes.
If I had a sig, it would probably go here.
|
|
|
|
|
Well, you can extract rows into a dataset and then use a foreach on the DataRows. For instance:
foreach (DataRow dr in dsDataset.Tables[0])
{
} Alternatively, you can pull the data out with a DataReader and loop through them using:
while (dr.MoveNext())
{
} Note that this is sometimes called a firehose cursor (something you may want to google).
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
That's what I was thinking, but how do I extract rows into a dataset?
If I had a sig, it would probably go here.
|
|
|
|
|
Well, one way to do this is:
DataSet ds ;
using (OleDbConnection conn = new OleDbConnection("myConnectionDetails"))
{
using (OleDbDataAdapter cmd = new OleDbDataAdapter ("myCommand", conn))
{
conn.Open();
try
{
cmd.Fill(ds);
cmd.Close();
}
finally
{
if (conn.State == ConnectionState.Open)
conn.Close();
}
}
}
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
Thanks, I'll try that!
Hippophobia- Fear of horses. What... What?
|
|
|
|
|
And is there a way to put the data from the DataSet back into the database?
Hippophobia- Fear of horses. What... What?
|
|
|
|
|
I recommend buying a book on ADO.NET, and perhaps one on SQL ( from the sounds of it )
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Hi .I have following problem with DataGridView. I use DataGridView bound to collection of objects. One of the properties is of boolean type. It is bound to CheckBoxColumn. I would like to display number of rows that are checked immediately after user checks one of the rows. Unfortunately value is pushed to underlying source only after user leaves edited cell. Is there any way how to find how many rows is checked right after box is clicked.
|
|
|
|
|
does anyone know how to loop through a binding source?
so far i have been working with the code
foreach (DataRowView invoiceRow in invoicebindingsource)
{
}
but what if i only want to check one column? I am also a little unclear on how to address that info in the cell i am currently looking at
Thanks for any help you can give
|
|
|
|
|
crash893 wrote:cell i am currently looking at
what does "looking at" mean?
|
|
|
|
|
test or manipulate
messagebox.show(something.tostring())
i am also trying to figure out how to do something like
if something.tostring() containes stringtext
{
replace something.tostring with stringreplace
}
|
|
|
|
|
crash893 wrote: test or manipulate
so if replace "looking at" in your first post with "test or manipulate".....
crash893 wrote: I am also a little unclear on how to address that info in the cell i am currently testing
I struggle to understand your posts. All I can do is guess that you are asking how to access the "columns" in the DataRowView . I really hope this is a school project. Anyway, I recommend you "read" some documentation on DataRowView from the MSDN Library which is available online from Microsoft. Also there are many MANY articles here on CodeProject that contain sample code for working with Database related issues. I would bet some of them show how to access columns of a DataRowView.
|
|
|
|
|
Hi
Sometimes Paint event handler throws exception "Current object used elssewhere"...
For example:
private blablabla_Paint(object sender, PaintEventArgs e)
{
Graphics gr = e.Graphics;
...
gr.DrawLine(...); //<---- Usually it happens here.
}
locking of "gr" object hasn't helped... what can I do with it???
Sorry for my bad English... =)
|
|
|
|
|
Oleg Mehechkov wrote: gr.DrawLine(...); //<---- Usually it happens here
if that is where it happens, you should show the line as is, and not part of it and
some elipses. Actually, you should show the entire method.
How do you expect anyone to help you now ?
show the exact line; and if it contains operators (new, +, &, /, whatever) split
the line, introduce local variables, and let the exception pinpoint which part of the
original line got bombed.
Oleg Mehechkov wrote: Usually it happens here
And where else does it also happen ? Show us that method too !
|
|
|
|
|
You're not trying to do graphics processing on multiple threads are you? This is, quite often, the cause of the InvalidOperationException that you are seeing.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
And how I can correct this bug???
Sorry for my bad English...
|
|
|
|
|
Hi everyone,
I'm using an AxWindowsMediaPlayer to play videos. At certain points when the program is running, I need to know exactly where in the movie I am (time or frame number). Any ideas?
Thanks,
|
|
|
|
|
I am writing a windows service that uses NHibernate for performing database access. Now, for debugging and other purpose, i am using log4net that prints log messages and thus we can keep track of the works of the service.
But the problem is- if i set log priority to INFO, it prints loads of unnecessary messages related to NHibernate. I want to block these NHibernate info's and want to keep only those messages that i wrote myself(log.info). I don't know where these NHibernate messages are coming and i need a way to stop them.
How can i disable the log messages that are automatically written by NHibernate ? Can i filter them out and keep only my log info's ? Please help if any one have any idea....
Thanks
Chayan
|
|
|
|
|
Iftekhar Naim wrote: Can i filter them out and keep only my log info's ?
Have you read the Log4Net documentation?
|
|
|
|
|
well, thanks for your reply. I did not actually read the documentation and i was just working according to a sample code. So i had no idea about filter. Now i read how to filter or block log messages. I couldn't make filter work yet. But now it is working using this-
category name="NHibernate"
level value="Error"/
category
So only error messages will be shown now. Please let me know if there is any other better solution. Thanks a lot
-- modified at 1:42 Wednesday 25th July, 2007
Chayan
|
|
|
|
|
I've started learning about generics, and am hoping to implement it in a project at work, to make things a bit easier.
I understand you can set a constraint on the generic where, for example, the generic class must have a public empty constructor, ie
public class MyClass<T> where T : new()
My question is, is there any way where I can create a constraint where T must have a constructor that accepts an object as an argument? For instance;
public class MyClass<T> where T : new(Object)
I've tried this, and get a compilation error, and from what research I've done in the MSDN documents, it doesn't look like I'll be able to.
Thanks for any help
|
|
|
|
|
Your research is quite (and annoyingly) correct.
I'm largely language agnostic
After a while they all bug me
|
|
|
|
|
Bah! Just as I suspected. Thanks anyway...
|
|
|
|
|
Your post might imply a factory problem, have you considered a factory solution in your design?
Also "Object" is un-typed. It seems that mixing it's use with Generics which are a "Typed" solution might be contradictory depending on the unknown requirements of your project.
|
|
|
|
|
Thanks for your reply, but I guess I should've been more clear with my original message. I don't want to pass a literal Object, I would like to pass an instance of a class that is used for interaction with a database that a coworker has written.
I am not too enthusiastic about using these objects, but I am required to. I was at least trying to find a way that would make it a little less painstaking. Thanks for your help though.
|
|
|
|