|
Cool, and you're welcome
Bastard Programmer from Hell
|
|
|
|
|
I have wrote C# programs similar to the one that I am working on right now time and time again, but on this particular occasion, I am having issues in making my code insert values into an Access Database. BTW, I am using Visual Studio 2010 and .net 4. Maybe it is something with .net 4...... Anyway, this is my code
private void btnAddRecord_Click(object sender, EventArgs e)
{
this.Cursor = Cursors.WaitCursor;
string connstr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=Steinar.accdb";
OleDbConnection conn = new OleDbConnection(connstr);
da.InsertCommand = conn.CreateCommand();
da.InsertCommand.CommandText = "INSERT INTO Returns" +
"(DateReceived, Dealer, Department, CustomerName, Address, Zip, City, Email, Phone)" +
"VALUES(@DateReceived, @Dealer, @Department, @CustomerName, @Address, @Zip, @City, @Email, @Phone)";
AddParams(da.InsertCommand, "DateReceived", "Dealer", "Department", "CustomerName", "Address", "Zip", "City", "Email", "Phone");
DataRow row = dt.NewRow();
dt.Rows.Add(row);
totalRecord = dt.Rows.Count;
currRecord = totalRecord - 1;
this.Cursor = Cursors.Default;
}
private void AddParams(OleDbCommand cmd, params string[] cols)
{
foreach (string col in cols)
cmd.Parameters.Add("@" + col, OleDbType.Char, 0, col);
}
I have set breakpoints and the AddParams method never executes... I can't figure out why it doesn't but it doesn't.
Can anyone see what I have wrong in this code? I am declaring all of my globals inside the class declaration
private OleDbDataAdapter da = new OleDbDataAdapter();
private OleDbConnection conn = new OleDbConnection();
private DataTable dt = new DataTable();
private DataSet ds = new DataSet();
int currRecord = 0;
int totalRecord = 0;
Any help would be greatly appreciated.
|
|
|
|
|
When you say "It never executes" what do you mean?
Have you put a breakpoint on the
this.Cursor = Cursors.WaitCursor; Line, and stepped into through the method?
Or just put a breakpoint on the
foreach (string col in cols) and never hit it?
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|
|
I should have been clearer on that because you raised an excellent question.... I placed a breakpoint on the initial cursor change and then stepped through the code. When it gets to the call to AddParams, it seems to read that line of code, but it never executes that method. Instead, it just steps on to the
DataRow row = dt.NewRow(); line. Of course, that can't execute either. It seems to read all the code. I even added a message box right after where I call the default cursor back and the message box will display, so it is reading through the code, but it just will not execute.
|
|
|
|
|
Premisoft wrote: it just steps on to the
Did you use F10 or F11?
Why is common sense not common?
Never argue with an idiot. They will drag you down to their level where they are an expert.
Sometimes it takes a lot of work to be lazy
Please stand in front of my pistol, smile and wait for the flash - JSOP 2012
|
|
|
|
|
Hello
Does someone knows either
1- Is there an altenativer to Winmm.dll on Windows CE CF ?
2- Or is there some class that can be used on CF to read Microphone and play sound ?
Thanks for any help
|
|
|
|
|
I need to implement collision detection algorithm for a program i'm working on. The objects i have here is ball/circle and a rectangle. The balls are moving vertically, while the rectangle is moving horizontally. The condition is that if the ball and rectangle touch each other then an event should be raised. I have been trying to do that for a while with my colleague but without success. This is my first program in C# so please bear with me.
|
|
|
|
|
|
I checked the article you referred me to. This example makes use of vectors and i didn't use vectors. However, I'll make time to study it.
|
|
|
|
|
Circle-rectangle is pretty straightforward: translate the circle into the rectangle's local space and check its distance to all four sides. If the circle is small you should also check if the centre is inside the box.
|
|
|
|
|
Thank you. Can you please guide me on how to do those calculations on distance and translating the circle into rectangle's local space. Right now its still not clear to me of how i could do that, maybe its because i'm still a novice in c#. Even a simple pseudo-code will help.
thank you
|
|
|
|
|
It isn't really a C# question, the algorithm looks the same in any C family language. It also depends how you've defined your rectangle (a circle will be centre and radius I assume). But essentially it goes like:
1. find the coordinate shift needed to place the rectangle with its centre at (0,0) and its sides along the X and Y axes
2. apply this same shift to the centre point of the circle
Now you can check whether the centre of the circle is inside the possible collision region which is a rectangle of half-size [hw + r, hh + r] centred on the origin (hw and hh being the half-width and height of the initial rectangle). If it's inside this box, if it's in one of the four corner nibbles you check the distance from the relevant corner point (collision if r² > |circle centre - corner|²), otherwise there is a collision.
|
|
|
|
|
Just want to make sure i understand what you are saying
Lets say we have rectangle with dimensions X1,Y1
and circle with Centre point x,y.
i have the values of all Xs and Ys
So checking if the circle is inside the possible collision region
1/2(width + radius), 1/2(height + radius)
if its outside
radius*radius>| circle center - corner|^2. Im sorry i dont understand can you please clarify.
For example you can explain it by something more or less like this, for rectangle with coordinate (x1, y1, w, h) and circle(x2,y2,r)
if (x1 > x2 + r || x1 + 30 < x2 || y1 > y2 + r || y1 + 30 < y2)
it could be more clearer if you can put explain it this way
Thanks
|
|
|
|
|
If your rectangle is already axis-oriented you don't have to rotate, so the transformation is trivial: the circle's centre in rectangle space is (x2-(x1+½w), y2-(y1+½h)). Call this [x' y'].
Now check if the circle is possibly colliding:
if(!(x' in range [-(r + ½w), r + ½w]) || (y' in range [-(r + ½h), r + ½h])) no collision;
That accounts for the 99% case where there is definitely no collision, and you can avoid any further processing.
Then check the easy cases:
if((x' in range [-½w, ½w]) || (y' in range [-½h, h])) collision;
Finally check distance to corners. The closest corner is the closest independently along the two axes:
var dx1 = x' - ½w, dx2 = x' + ½w, dy1 = y' - ½h, dy2 = y' + ½h;
var dx_closest = min(dx1, dx2), dy_closest = min(dy1, dy2);
if(r² > (dx² + dy²)) collision;
|vector| is the vector magnitude function, i.e. distance; in a standard 2D system this is the Pythagorean distance as expanded above.
If you care about the collision vector, in the easy case it is [1, 0], [-1, 0], [0, 1] or [0, -1] depending on which side you intersected with, and in the closest-corner case it is along [dx_closest, dy_closest].
|
|
|
|
|
hi, here is how i tried putting all this in code. and i got the error
{"Object reference not set to an instance of an object."}
Im sure that has something to do with my code here it is
public class Ball
{
Player square;
public float x, y, yvel, radius;
public Brush brush;
public Ball(int gameWidth,int gameHeight,Random r)
{
x = r.Next(gameWidth);
y = r.Next(gameHeight);
yvel = r.Next(2) + 2;
radius = r.Next(10) + 5;
brush = new SolidBrush(Color.Blue);
}
public void Move(int gameHeight)
{
if (y + radius >= gameHeight - 315)
{
y = 0;
}
y += yvel;
if ((y + radius) > gameHeight - 315 && collision(square))
{
MessageBox.Show("Collision");
}
}
public void Draw(Graphics g)
{
g.FillEllipse(brush, new RectangleF(x-radius,y - radius, radius * 2, radius * 2));
}
public bool collision(Player player)
{
float X = (x - (player.x + 15));
float Y = y - (player.y + 15);
return (!(-(radius + 15) < X || X < (radius + 15) || -(radius + 15) < Y || Y < (radius + 15)));
}
}
|
|
|
|
|
This exception is usually easy to track down. You passed a null to something, and you can tell what from the line it's thrown on. Have a look at that line, see what object you're trying to call methods on and then see why you passed a null.
(clue: you never assign Player)
|
|
|
|
|
I am trying to do a program about imageprocessing. I want to firstly object tracking I use meanshift algorithm but I take video frames on disk, I have to fast so How can I get video(only Y from YUV) from usb cam buffer?
|
|
|
|
|
Hi,
I have class library in my project and i wanna to encrypt it so when i build my project if any one use tools to open my project source(like resource hacker) can't see the class.
|
|
|
|
|
Google for "obfuscator".
Binding 100,000 items to a list box can be just silly regardless of what pattern you are following. Jeremy Likness
|
|
|
|
|
As Richard says, Obfuscation is the way to go - but do not expect it to be foolproof. Remember that the processor has to be able to read your code in order to execute it, so a competent and determined programmer can too!
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|
|
You can use Assembly.Load(byte[]) to load a binary image. Thus one can load an encrypted file, decrypt it, then load it as an assembly.
|
|
|
|
|
This is the road I've gone down. (I encrypt by the licence information file, so if you change that, the program won't run.) But once someone gets a running version, they can decompile the shell, make it dump the working inner assembly to disk and look at it, or link to the shell assembly and grab the inner one while it's running.
|
|
|
|
|
|
No. Don't even go down that road. If you really want to protect your code, hide it behind a webservice (and even then the server is going to get hacked someday and someone will have your code). Otherwise the code has to be decryptable by the user - how else is he going to run it? You can put a nice big lock on a door, if you put the key under the mat it's still useless. Until processors implement public key encryption (and I hope to god they never will), there is nothing you can do.
You can obfuscate the code, but remember that it won't stop anyone but a bored teenager in his moms basement. And maybe not even him.
|
|
|
|
|
I am trying to draw two paraller curves side by side.
Width of both curves should be increased or decreased. Also the sweep angle is variable and can be increased or decreased. What is the best possible way to do this using C#?
I am actually writing this for Paint.Net but for support I am writing this code first in visual Studio using C#.
|
|
|
|
|