|
assuming ds is a DataSet, that line would throw a NullRefExc only if ds were null or there were no table called "category"
suggestion: split the line into many, and check what gives
if (ds==null) MessageBox.Show("ds is null");
DataTable dtCat=ds.Tables["category"];
if (dtCat==null) MessageBox.Show("dtCat is null");
DataColumn c1=dtCat.Columns["ID"];
MessageBox.Show("we got a DataColumn!");
|
|
|
|
|
System.NullReferenceException is an exception that never lies. You are obviously typing a string in wrong.
To eliminate all possible confusion, try this code:
if (!ds.Tables.Contains("category") || !ds.Tables["category"].Columns.Contains("ID"))
throw new ArgumentException("The category table or column does not exists!")
if (!ds.Tables.Contains("item") || !ds.Tables["item"].Columns.Contains("catID"))
throw new ArgumentException("The item table or column does not exists!")
DataColumn c1 = ds.Tables["category"].Columns["ID"];Line
DataColumn c2 = ds.Tables["item"].Columns["catID"];
dRel = new DataRelation("categoryItem", c1, c2);
The mind is like a parachute. It doesn’t work unless it’s open.
|
|
|
|
|
Thanks for the reply. yes you were right. it threw the argument exception. the query i used for the dataset ds is:
select i.ID,j.Item,j.catID from category i, item j where i.ID = j.catID
and the dataset is having data . Then why it gave that error ?
suchita
|
|
|
|
|
Which one threw the exception? I agree with Eddy that you need to learn how to perform effecient debugging.
Visual Studio wouldn't be worth two cents to me if it didn't have a good debugger.
The mind is like a parachute. It doesn’t work unless it’s open.
|
|
|
|
|
Thank you. Both of the argument exception is executing.
suchita
|
|
|
|
|
ok now i changed them a little bit.
string query = @"select i.ID,j.catID,j.item from category i, item j where i.ID = j.catID";
SqlCommand objCmd = new SqlCommand(query, cnx);
SqlDataAdapter objDA = new SqlDataAdapter(objCmd);
DataSet ds = new DataSet();
objDA.Fill(ds,"category");
objDA.Fill(ds, "item");
DataColumn c2 = ds.Tables["category"].Columns["ID"];
DataColumn c1 = ds.Tables["item"].Columns["catID"];
dRel = new DataRelation("category_Item", c1, c2);
ds.Relations.Add(dRel);
And here ID is the unique key for category and catID is the foreign key . But it throws error like:
These columns don't currently have unique values.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ArgumentException: These columns don't currently have unique values.
Source Error:
Line 1231:
Line 1232: dRel = new DataRelation("category_Item", c1, c2);
Line 1233: ds.Relations.Add(dRel);
Line 1234: Repeater1.DataSource = ds;
Line 1235: Repeater1.DataBind();
But in ID is the unique key in category table and i have unique ID in item table too. I tried replacing catID by ID for the item table but in both the cases, error is same.
suchita
|
|
|
|
|
Thank you so much to all who has given interest in this topic. i got my program running now.
suchita
|
|
|
|
|
Hi everybody. I'm developing an application that sends keystrokes to another background application. The problem is that i have so send a "Alt+F", but i can't get it to work.
I'm using PostMessage:
[DllImport("User32.Dll", EntryPoint = "PostMessageA")]
private static extern bool PostMessage(IntPtr hWnd, uint msg, int wParam, int lParam);
const int VK_ALT = 0x12;
const int WM_KEYDOWN = 0x100;
PostMessage(hWnd, WM_KEYDOWN, VK_ALT, 0);
PostMessage(hWnd, WM_KEYDOWN, VK_F, 0);
The result is that the background application "see" the "F", but no the "Alt".
Anybody has any idea how to fix it or how to do this without using SendKeys? Because the background application used to be minimized.
Greetings and thanks in advance.
|
|
|
|
|
hi,
i have in mind to use the lPama for the modifier controls
PostMessage(hWnd, WM_KEYDOWN, VK_F, VK_ALT);
greetz
|
|
|
|
|
Thanks for both quick replies, but it doesn't seems to work
Is there other way to do this? I can't use sendkeys because the application is minimized.
Thanks
|
|
|
|
|
If you understand C/C++ here is an old example where I send Ctrl+f to some window (hWnd).
HWND hOldForegroundWindow = ::GetForegroundWindow();
::SetForegroundWindow(hWnd);
::ShowWindow(hWnd, SW_MAXIMIZE);
::SetFocus(hWnd);
Sleep(100);
INPUT inputs[2];
memset(&inputs[0], 0, sizeof(INPUT) * 2);
inputs[0].type = INPUT_KEYBOARD;
inputs[0].ki.wVk = VK_CONTROL;
inputs[1].type = INPUT_KEYBOARD;
inputs[1].ki.wVk = 70;
::SendInput(2, &inputs[0], sizeof(INPUT));
Sleep(100);
inputs[0].ki.dwFlags = KEYEVENTF_KEYUP;
inputs[1].ki.dwFlags = KEYEVENTF_KEYUP;
::SendInput(2, &inputs[0], sizeof(INPUT));
Maybe in your case you just have to wait some short period of time and send a KEYUP event.
Greetings
Covean
|
|
|
|
|
Hi, thanks for your reply, but the problem is that i need to do this without setting focus on the application .
I'm trying to do this with the notepad (for test), sending CTRL+F to open the "Search" window, but when i run the application, the notepad shows a "F" in the edit area. I don't know why it's ignoring the "CTRL".
|
|
|
|
|
1. I think in this case you can't use the SendKeys function, because they send the input to the window that has the focus.
Can't you just switch the focus for this very short period of time to your app and than back to the app that had the focus before?
2. Ever tried to send KEYDOWN at first (try with ALT modifier set/unset) and after you sent left ALT + some key just sent an KEYUP event?
Something like this:
PostMessage(hWnd, KEYDOWN, VK_LEFTALT);
PostMessage(hWnd, KEYDOWN, VK_F);
Sleep(100);
PostMessage(hWnd, KEYUP, VK_F);
PostMessage(hWnd, KEYUP, VK_LEFTALT);
Greetings
Covean
|
|
|
|
|
Hi! I found the solution! it is a mix between a sendkeys and postmessage, that works
First, set the "ControlKey" to "active" (i think it's like if we "press" the keyboard controlkey), then send the PostMessage to the hWnd (application), and then restore the "ControlKey" state.
keybd_event(VK_CONTROL, (byte)MapVirtualKey(VK_CONTROL, 0), 0, 0);
PostMessage(hWnd, WM_KEYDOWN, (uint)VK_F, 0);
keybd_event(VK_CONTROL, (byte)MapVirtualKey(VK_CONTROL, 0), 2, 0);
Thanks to all for the replies.
|
|
|
|
|
I think the problem is, that you send an ALT key but not left or right ALT, what is a big difference for the OS.
VK_ALT is only used in user application the simplify some things.
1. send VK_LEFTALT = 0xA4 or VK_RIGHTALT = 0xA5
or
2. use SendKeys.Send
or
3. Have a look at (low-level) windows key hooking (SetWindowsHookEx). This helps the understand how key strokes are queued in the windows messaging system.
Greetings
Covean
|
|
|
|
|
Hi,
When i am running a browser ( which i was created in windows application ), no one should kill my processes through Task Manager. How can i do this.
Thanks.
krishna
|
|
|
|
|
You can't. Many others have asked that over the years. You probably won't be the last either.
|
|
|
|
|
I don't know of a way to do this, and I'd strongly consider beating you severely if you did this to me. I stopped using Internet Explorer because I got tired of it launching multiple instances of itself that consume 100% of resources over time. Acrobat Reader does the same thing. Without the ability to kill a process in Task Manager, your application is no better than a virus.
That being said, certain users in a business environment should be restricted from accessing Task Manager at all. That's simply good security practice, and can be accomplished by an Administrator using Group Policies. Look into Group Policy management if you want to do this for a legitimate reason.
"A Journey of a Thousand Rest Stops Begins with a Single Movement"
|
|
|
|
|
You can't. Since your app is launched by the user, it runs AS the user. The user can kill any process they launch and there's nothing you can do about it.
|
|
|
|
|
You can, actually.. at least under XP. But that would make your program malware, so I'm not going to help with that.
On a related note, you can easily (without hacks) make it so that your program will not close when "killed" from the Applications list. It can still be closed from the Processes list, so that wouldn't make it malware.
If you have a Form, subscribe to the FormClosing event and set e.Cancel to true .
|
|
|
|
|
You can have your processes save their state at regular intervals, and run a second "shadow" process that monitors the primary processes.
When the shadow process detects that one of the primary processes was stopped (e.g. with Task Manager), it restarts that process, using that process' saved state to pick up where it left off.
|
|
|
|
|
krishnavaradharajan wrote: no one should kill my processes through Task Manager.
And what are you going to do, if the user tripped the power cable? Why do you want to prevent the user from killing your buggy application.
|
|
|
|
|
hi,
the easy way would be to disable the taskmanager for the user using policies.. it sounds like the user will have no ability to to certain changes on the system either, so would be using policies the right way if not it would be a way too =)
|
|
|
|
|
Remember that it is your software, but it is not your computer! All the tricks you can apply to prevent the owner of the computer from closing an application running on it could be considered as not politically correct!
|
|
|
|
|
Can you tell us why you'd like to implement this behavior? There may be a more acceptable means of meeting your requirements (which may be perfectly valid), but it's hard to guess without a use case. If you stated the big picture, you may get some helpful replies.
/ravi
PS:
I've often fallen into this trap myself. When I ask someone how to do something, I invariably end up at a better solution by answering why I'd like to do this (i.e. what's the end result I'm trying to achieve).
|
|
|
|