|
I am trying to grasp how to use select, update, insert and delete command.
I tried reading from some books Programming C# by Oreilly but it just doesnt really explain it in detail.
I was hoping if anyone can point me to some article (don't seem to have them at code project) where i can learn how to perform the above operations on MS ACCESS databases.
thanks
|
|
|
|
|
Look at OleDbConnection or OdbcConnection (Framework 1.1, some people have indicated that ODBC seems to perform better than OLE DB when invoked from C#).
Simple example:
using ( OleDbConnection conn = new OleDbConnection() )
{
conn.ConnectionString =
@"Provider=Microsoft.Jet.OLEDB.4.0;" +
@"User ID=Admin;" +
@"Data Source=FPNWIND.MDB;" +
@"Mode=Read|Share Deny Read|Share Deny Write";
using ( OleDbCommand cmd = new OleDbCommand() )
{
cmd.CommandText =
"SELECT CategoryName FROM Categories ORDER BY CategoryID";
cmd.Connection = conn;
conn.Open();
OleDbDataReader rdr = cmd.ExecuteReader();
try
{
while ( rdr.Read() )
{
System.Console.WriteLine(
"Category: {0}",
rdr.GetString( 0 ) );
}
}
finally
{
rdr.Close();
}
}
} To try this, create a new C# console application, paste into Main and add using System.Data; using System.Data.OleDb; at the top.
This code opens the FPNWIND.MDB database (supplied with Office 2000) and outputs a list of all known categories to the console.
For simple manipulations of data, use OleDbCommand 's ExecuteXxx functions. If you don't expect any results (for example, if you're running an INSERT , UPDATE or DELETE statement), use ExecuteNonQuery . If you only want a single data value (the first column of the first row of the results), use ExecuteScalar .
If you have an OleDbDataReader open on a connection, you can only scroll forwards through the data, and you cannot modify the data. You cannot do anything else with that connection until you have either read all the data (Read returns false ) or have closed the reader.
ADO.NET does not have an equivalent of classic ADO's live update of recordsets. The closest is essentially a batch mode involving a DataSet (an offline cache of one or more DataTable s) and an OleDbDataAdapter . DataSet and DataTable are general classes; you use a DataAdapter from the appropriate provider to fill the data set or table and reflect any modifications back to the data source.
|
|
|
|
|
Is it possible to hook(MouseHook) another process/application using C# ?
VikramS
|
|
|
|
|
|
Hi,
i used ControlPaint.DrawCheckbox() method, but the checkbox is not drawn with XP Theme (FlatStyle.System). Is it possible to use ControlPaint class with XP Styles?
.:[Greetz from Jerry Maguire]:.
|
|
|
|
|
It doesn't seem like it. You might want to use this[^] instead.
|
|
|
|
|
Try calling Application.EnableVisualStyles(); in Main before anything else. This mostly worked for me (I'm still having problems with my toolbars not looking right.)
When all else fails, there's always delusion.
- Conan O'Brien
|
|
|
|
|
Yep, you're right, my code is
Application.EnableVisualStyles();
Application.DoEvents();
Application.Run(new MyForm());
otherwise the styles are not set right, i guess it's a framework error that i have to call DoEvents().
I have found a solution do draw controls theme aware via xp theme api, thanks.
.:[Greetz from Jerry Maguire]:.
|
|
|
|
|
Hi, how do you minimize your app to system tray in C#/.NET?
norm
|
|
|
|
|
Add a NotifyIcon to your form and assign it an icon.
set visible = false if you do not want it to be there all the time.
In the event handler where you want the app to minimize to the tray do something like:
private void btn_MinimiseToTray_Click(object sender, System.EventArgs e)
{
this.WindowState = FormWindowState.Minimized;
this.ShowInTaskbar = false;
this.notifyIcon1.Visible = true;
}
and reverse it all when the icon is clicked or on a context menu etc....
|
|
|
|
|
Thanks! I successfully send the app to system tray. But I am having some trouble trying to restore it from the tray.
private void NotifyIcon_Clicked(object sender, System.EventArgs e)
{ //None of this help, the form just disappeared, never to come back.
WindowState=FormWindowState.Normal;
ShowInTaskbar=true;
BringToFront();
Focus();
Visible=true;
return;
}
I just need one more tip for this.
norm
|
|
|
|
|
did you try Activate() ?
Free your mind...
|
|
|
|
|
Thanks. But, yes I did. Activate didn't work
norm
|
|
|
|
|
Hi Guillermo, I've got it working - well, the title bar didn't get repainted properly. Part/Chunk of it (Titlebar) appears dark. I called Invalidate(), which got rid of the problem in client area, not the title bar...
private void NotifyIcon_Clicked(object sender, System.EventArgs e)
{
WindowState=FormWindowState.Normal;
ShowInTaskbar=true;
BringToFront();
Focus();
Visible=true;
ClientSize = new System.Drawing.Size(292, 318);
Location = formLocation;
Invalidate();
return;
}
private void Form_Clicked(object sender, System.EventArgs e)
{
formLocation = this.Location;
WindowState = FormWindowState.Minimized;
ShowInTaskbar = false;
notifyIcon.Visible = true;
return;
}
norm
|
|
|
|
|
Good.
When I did it, I used Form.Hide() instead of changing the windowstate, so I didn't have the problem of repainting. When I clicked on the taskbar icon, I used Form.Show(). In that way, it did good for me..
Free your mind...
|
|
|
|
|
Thanks, it's working just fine now. I hide the form, as supposed to minimizing it.
norm
|
|
|
|
|
What i am doing is to generate a TrayIcon and use this code:
// Public Bool for Closing the app
bool boolAlowClose = false;
// Press the closing Button at the app
protected void frmMain_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
if (!boolAlowClose)
{
this.m_notifyicon.Visible = true;
this.Hide();
e.Cancel = true;
}
else { e.Cancel = false; }
}
// ContextMenu from Trayicon to view the app again
private void cmnu_View_Form_Click(object sender, System.EventArgs e)
{
this.m_notifyicon.Visible = false;
this.Show();
}
// This is the Menu "Close" hat close the application
private void cmnu_Menu_Close_Click(object sender, System.EventArgs e)
{
boolAlowClose = true;
this.Close();
}
Hope this will help!
Matthias
|
|
|
|
|
|
im writing a new control, and i need to pass information to the click event, how do i add data to then EventArgs so that when i create a new project and place this control in the form , the click even of that control will give me more data inside the EventArgs?
(i know i can create a class the inherits from EventArgs and add the info in there but what do i need to do, so that it will send that new class to the on_click event)
void on_click(object sender, System.EventArgs e)
|
|
|
|
|
Hi,
why you need to serve the data via the event? It's also possible to say:
void OnClick(object sender, EventArgs e)
{
((MyControlType)sender).MyDataProperty ...
}
you could read and write everything you need there.
.:[Greetz from Jerry Maguire]:.
|
|
|
|
|
You need to:
1) inherit from the System.EventArgs class with a new class eg:
public class MyControlEventArgs<br />
{<br />
private string AnExampleDataMember<br />
}
Then create a delegate for that type of event
public delegate void MyControlEventHandler(object sender, MyControlEventArgs e)
And then create the event using the newly created delegate.
Create data memebers in MyControlEventArgs for all the data you need to pass into the event. Pass an instance of the new args class into the new handler.
Cheers, James
James Simpson
Web Developer
imebgo@hotmail.com
|
|
|
|
|
|
hi , nice article but you are missing the point, maybe i didnt explain clearly. what i want to do is create a control, so that when i create a project and place the control in the form, i will look at the control's properties and press the events button, now if i double click on the event click in [action], it will create a new function like allways , but instream of getting a :
private void Control1_Click(object sender, System.EventArgs e)
{
}
i will get something like
private void Control1_Click(object sender, System.EventArgsWithExtraInfo e)
{
}
hope this is clearer now
|
|
|
|
|
What is your problem, just design your events as I explained in that article.
Also, for setting an event as an defult event, you should put (as I remember) below attribute above your event defenition in your event owner class:
[DefaultProperty]
Don't forget, that's Persian Gulf not Arabian gulf!
|
|
|
|
|
Hi, Currently I am using Excel 8.0 COM object to display information from C# to Excel. The codes i am using is from the net. However, there is always an error. I tried many different codes from different website, it still won't work. Would the different version of COM object be the reason of those errors? Does different version make a difference?
|
|
|
|