|
i want to make an oledbCommand with a variable as in sql @variable..SELECT *Table From Table WHERE Column=(thatvariable),how can i declare this to use in my code, am using Microsoft Access
|
|
|
|
|
OleDbConnection oleConn = new OleDbConnection(<myconnectionstring>);
oleCOnn.Open();
OleDbDataAdpater oleAdapter = new OleDbDataAdapter("my select statemnent", oleConn);
DataSet ds = new DataSet("Access");
oleAdapter.Fill(ds, "MyTable");
now I would check the parameters because its been 2 weeks since I connected but it should work fine
ohh yeah to test
DataGrid1.DataSource = ds.Tables["MyTable"];
I'm not an expert yet, but I play one at work. Yeah and here too.
|
|
|
|
|
thx Ista for replying , but that wasnt my question i was just asking about how to declare an oledb parameter as in SELECT *Table From Table WHERE Column=(parameter),as declared in sql we use "@" b4 the parameter i was just asking wat i ll declare in ole instead of that "@".
|
|
|
|
|
doh
its just like the sql
myOleCommand.Parameters.Add("@Param1", OleDbType.SmallInt);
refer to it as
myOleCommand.Parameters["@Param1"].Value = 1;
i use a short way when assigning many
OleDbParameterCollection olePar = myOldCommand.Parameters;
olePar.Parameters.Add("@Param2", OleDbType.VarChar, 10);
olePar["@Param2"].Value = "Hey dude";
I think that answers it. Sorry for the confusion.
nick
I'm not an expert yet, but I play one at work. Yeah and here too.
|
|
|
|
|
thx Ista really for replying again
but i still ve the problem!
this is my debug error :
@PostionIndex error: managed EE does not understand expression's syntax
the code :
OleDbCommand cmd = new OleDbCommand("SELECT * FROM Phones WHERE Contact = @PostionIndex");
cmd.Parameters.Add("@PostionIndex", OleDbType.SmallInt);
cmd.Parameters["@PostionIndex"].Value = int.Parse(this.editID.Text);
|
|
|
|
|
change it for a question mark
check this link out
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemDataOleDbOleDbCommandClassParametersTopic.asp
and for info and parameter arrays
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemdataoledboledbparameterclasstopic.asp
its like OleDbParameter[] oleParam;
but I would just stack them on. like in your code, just replace the parameters with ? and make sure you add them in order.
nick
I'm not an expert yet, but I play one at work. Yeah and here too.
|
|
|
|
|
I've been dealing with this problem off and on for the past couple weeks, and I'm stumped.
I have a Panel that I've been using as a desktop for my app, and on this desktop are many custom controls I've also extended from Panel. I'm trying to draw arrows between some of the custom controls. That has worked fine until I had to deal with scrolling. I'd like for the arrows to be drawn correctly on this virtual desktop, so if a custom control is barely outside the viewport, the arrow should be pointing in exactly that custom control's direction. Alas, I have arrows pointing in the wrong direction.
One of the problems is that the Location property doesn't seem to take into account the virtual location, after scrolling. So, it seems that two different controls can both be at Location (100, 0), even if they might be 1000 pixels apart in the virtual space. Somehow Windows Forms knows to display only the controls that belong in that viewport, but I can't figure out how to extract the virtual coordinates... and using them with DrawLine() would be even more useful.
PointToScreen() and PointToClient() don't seem to help. AutoScrollPos seems to be the way to go, maybe, but I haven't been able to do anything useful with it.
Does anyone have any tips and tricks for working with GDI+ and custom controls on a scrollable control (Panel)?
Thanks,
Arun
|
|
|
|
|
While I can't discuss issues specific to the Panel control, I can give you some insight into problems I overcame when extending the ListView to provide control container functionality - perhaps it can help.
In my control, I needed to get the actual pixel location of each ListViewItem's SubItem in the ListView - taking into account the current scroll position. I'm guessing that your situation is similar.
The first task was to find each controls location, relative to it's container:
int x = Left;<br />
for (Control thisParent = Parent; thisParent != null; thisParent = thisParent.Parent)<br />
{<br />
if (thisParent.Parent != null && thisParent.Left > 0)<br />
x += thisParent.Left;<br />
}<br />
<br />
int y = Top;<br />
for (Control thisParent = Parent; thisParent != null; thisParent = thisParent.Parent)<br />
{<br />
if (thisParent.Parent != null && thisParent.Top > 0)<br />
y += thisParent.Top;<br />
}
Once you've done this, you should have a good reference to everything, and can paint your lines etc. The only other thing you'll need to is is get notified of scroll events so you can repaint everything properly. For the ListView control, I was forced to override the WndProc method to get my notifications:
private const int WM_HSCROLL = 0x114;<br />
private const int WM_VSCROLL = 0x115;<br />
<br />
protected override void WndProc(ref Message msg)<br />
{<br />
if ((msg.Msg == WM_VSCROLL) || (msg.Msg == WM_HSCROLL))<br />
{<br />
}<br />
base.WndProc(ref msg);<br />
}
Naturally this could all be irrelevant to the Panel control (something I've never bothered to base a new control off), But I hope it helps anyway.
|
|
|
|
|
Interesting and insightful response, thanks! I fear that my lack of Win32/C++ makes me forget aboud WndProc().
I think the way to go might be to create and set a VirtualLocation in my child controls which get updated in a LocationChanged event handler. I may have to use WndProc() to create some HScroll and VScroll events -- odd, I think, that they aren't part of the Windows Forms library.
I still think it's odd that the Location property doesn't reflect the virtual location of the autoscrolling parent control, just that of the location within the viewport. It seems like one can use the Location property to move a child control to a virtual location, though.
Thanks,
Arun
|
|
|
|
|
OdbcDataAdapter da = new OdbcDataAdapter(sql,con);
DataSet ds = new DataSet();
da.Fill(ds,"Contacts");
dataGrid1.SetDataBinding(ds,"Contacts");
i need to get the total rows returned from my sql query similar to how ExecuteNonQuery() works.
how can i get the total rows in a data grid, data set, or data adapter?
|
|
|
|
|
Use ds.Tables["MyTable"].Rows.Count property to get the total number of rows in MyTable DataTable.
Alexandre Kojevnikov
MCAD charter member
Leuven, Belgium
|
|
|
|
|
|
For some reason DataSource,DisplayMember, and ValueMember don't seem to be properties of the CheckedListBox control. I even created a new project, dragged an new CheckedListBox and looked in the properties and tried to type it into the code.
This is my first time using this particular control with C#. In VB it still pops up in the Intellisence.
What am I missing?
Robert L. Edwards
|
|
|
|
|
public bool BeginsAlpha(string strToCheck)
{
System.Text.RegularExpressions.Regex pattern = new Regex("^[a-zA-Z]*");
return pattern.IsMatch(strToCheck,0);
}
BeginsAlpha("1") returns true no matter if my string starts with a letter or a number. What am I doing wrong here?
|
|
|
|
|
* means "0 or more characters", so when you try to match against:
3djd
you successfully match zero alpha characters.
If you get rid of the *, you'll have to match 1 character, which I think is what you want.
|
|
|
|
|
thank you! with that in mind, i used a + instead of a * and it worked great!
|
|
|
|
|
Hi,
Im looking to create a client/server c# application. I've been reading many articles on the subject, but the developers always seem to be arguing about the best practices after the article.
I was just wondering if anyone has any tips? to use synchronous or asynchronous, etc. Polling or Events etc?
I need to support upto 10 clients.
I've created a client/server app with Java before where (for the server) I created a thread to listen for connections, when a connection was made it passed the socket to a clientservice class and ran it in a new thread, then saved a pointer to the class in a vector array. Is this the same approach I should take with c#?
Thanks in advance,
Matt.
|
|
|
|
|
The best way is to allow for both synchronous and asynchronous calls. One thing that CP articles typically miss is reusability and portability. It's always better to make your application scalable and extensible so that clients can use it however they want (those posing restrictions isn't always a bad thing) and you could even mix sync and async calls. Sometimes one is better than the other - it just depends upon the circumstance. That's the server.
The client is a slightly different matter. The server should be an extensible architecture that scales. The client must choose how to use the server. In the case of Web Services, async methods are generated automatically (if you want). If there is a process in which you want the user to wait and it can't / shouldn't be cancelled - use a sync call. If they can cancel it or you want to update the UI or something while waiting, use an async call.
Now, if you use remoting, you have some further options. Providing scalability is important, but your hardware is limited no matter how big you are. You could always support a certain number of async calls, but after so long the hardware gets sluggish. You could inform your client apps (using channels for example) to start using sync calls to cut-down on the server load.
Basically, everything you're reading is right and wrong. There is no "right" or "wrong" way for every circumstance, but there are "right" and "wrong" times to use different techniques.
I know this answer is a little abstract, but I hope is solves your dilema.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Thanks very much for the detailed reply Heath, I've taken note of many of your points, Generally I think I need to put time aside to study the networking features of .net to better understand the best solution for my requirements.
Thanks Again,
Rgds, Matt.
|
|
|
|
|
To echo what Heath said, it depends on what your client server application is like. Which way does the information flow? Who initiaties the information transfer? What kind of latency requirements do you have?
To speak in general terms, if your clients ask for data and get back a response, you can choose your technology. Remoting gives you rich types, but only works with .NET programs, while web services give you reach but less richness in the type area. Neither are particularly good when the server needs to tell the client something asynchronously, though you can get away with polling or blocking calls until a timeout or something interesting happens.
Sockets give you the most flexibility, but you'll probably be writing a bit more low-level code. I wrote some C# code recently that does what you describe using sockets, and implements a nice event-based approach. The client calls a method on a object, which sends a message to the server. This gets rebuilt into an object on the server, and an event on the server object is fired. Same thing when the value comes back to the client. This gives you more flexibility, but moves you into a message-based approach rather than the RPC idiom that web services and remoting use.
Hope that helps.
|
|
|
|
|
Hi Eric,
The basics of my application is that the server will have a central msde database, and the clients will connect to the server to perform any data related tasks. Thats the basics of it, it may become more complex as development proceeds.
Im planning to use c# to develop the application.
Thanks for your help, I'll keep your comments in mind.
Regards, Matt.
|
|
|
|
|
I have a similiar approach also.
Clients need to rapidly change data in a database.
My approach is this for schedules and things I use the data layer approach, then use reflection to populate classes.
I found that some of the extensive tasks done to the database could wait to be updated so I logged those into queued components for com+
I have external customers accessing web services which I have services linked to and I also manipulate those external web services along with fax reading/writing, auto mailers and tech data which I run as services on another server to give the db server full optimization.
In other words I decided to take what features were instantaeous and what could wait and set a time for them to be processed.
I think .NET remoting in combination with COM+ is great in that it closely mimics the J2EE environment. You operate in lifetime cycles rather than concrete data.
my 1/2 a penny
nick
I'm not an expert yet, but I play one at work. Yeah and here too.
|
|
|
|
|
Message Closed
modified 29-Jun-15 10:36am.
|
|
|
|
|
mithunshanbhag wrote:
A good software to generate this tier can be found at http://www.sd.nl/software/llblgen.asp. This layer would automatically generate the connectivity Classes, Database Connection String and The Stored Procedures for your database (i used it on SQL Server 2000. dunno if it works for MS Access.)
Uhh why?
I mean its really extra work when you think about it. Its not the teams coding style, you have to spend extra time learning the style and how the communication is designed. Especially if it creates a lot of classes. Really code generators are a wiast of effort in my opinion, for a midsized project they cause more hurdles than thier worth. What about when something changes, it takes more time to leartn the code than write it. These were expressed in an article on this site but I cant remember which one it was.
And really does it use reflection to populate and a connection string, thats as simple as dragging a DataConnection onto your form in the IDE. And stored procedures are nothing but easy. I can create 50 of em in one day.
But then again thats my opinion.
nick
I'm not an expert yet, but I play one at work. Yeah and here too.
|
|
|
|
|
Message Closed
modified 29-Jun-15 10:35am.
|
|
|
|