|
Hi all,
Can someone help me how to read varbinary(max)in C#.
I've try this, but gives an error. Number 2 the column index in the table
<br />
byte[] binaryData = (byte[])thisReader.GetValue(2);<br />
Thanks
I appreciate your help all the time...
CodingLover
|
|
|
|
|
Hi,
what is the error message? Maybe the column value is DBNull?
Regards
Sebastian
|
|
|
|
|
This is the error I've
"Unable to cast object of type 'System.Int32' to type 'System.Byte[]'.<br />
I appreciate your help all the time...
CodingLover
|
|
|
|
|
Are you sure that you access the correct column? Your column is an integer. Remember that the GetValue()-method starts the column index at 0. So the second column has to be accessed by passing a 1 to the method.
Regards
Sebastian
P.S.: If this doesn't help, please post the sql query.
|
|
|
|
|
Ya, I got the point sir. Refer the incorrect index.
Now can you how can I convert that byte array into a string.
I appreciate your help all the time...
CodingLover
|
|
|
|
|
You can convert the byte[]-field into a base64-encoded string like this
string sEncoded = Convert.ToBase64String(aBytes);
Does the byte-field represent a string or something else (file etc.)?
|
|
|
|
|
I've try this, but shows some characters. But it's not what I expected.
In DB I've added some strings.
I appreciate your help all the time...
CodingLover
|
|
|
|
|
So what it is you are expecting?
|
|
|
|
|
hi all
I want to close all the applications which i opened and kept it in my system, when i close my c#
application
all should get closed when i close my c# application
is it possible to do?...if yes ple help me...
thanks in advance
|
|
|
|
|
Use the System.Diagnostics.Process class along with a List. You can start new processes using the Process.Start method and store the returned components in the list. Now when your application exits, call the Process.Kill method for all the elements in your list.
BTW, you're working for some company?
|
|
|
|
|
|
I tried adding in the list obj which i created but its not adding anything
|
|
|
|
|
Could you post the code?
Btw you cannot add sth to the process list, it is read-only.
|
|
|
|
|
Hello SeMartens,
I'm not talking about adding something to the process list, but to an instance of the
List class. Like the following code:
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
List<Process> list = new List<Process>();
string input="";
Console.WriteLine("Enter path to a program to start it.");
while (true)
{
input = Console.ReadLine();
if (input == "exit")
break;
try
{
list.Add(Process.Start(input));
}
catch
{
Console.WriteLine("Failed to start " + input);
}
}
foreach (Process process in list)
{
if (!process.HasExited)
process.Kill();
}
}
}
}
|
|
|
|
|
Hi Ankit Rajpoot,
I understood your post, but I don't know if sandhya14 did
Regards
Sebastian
|
|
|
|
|
ok..
see am giving like this..
System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo(@"Notepad");
System.Diagnostics.Process listFiles;
listFiles = System.Diagnostics.Process.Start(psi);
listFiles.Kill();
here what is happening is it is opening a new notepad and closing that
but i need to close the application which is already opened...
ex:- i have opend 3 browsers and 1 notepad already opened in my system...now am running my application.now if i close my application these 3 browser and 1 notepad also should get closed...
thats what am asking how can i add these already opened things in to my list?
|
|
|
|
|
Hi,
first you could use
System.Diagnostics.Process.GetProcesses();
to enumerate all running processes. But closing them could be difficult because you have to distinguish between system processes and application processes. A better way is to get all top-level applications (like the task-manager) and close them. Have a look at this link http://www.neowin.net/forum/lofiversion/index.php/t369213.html[^].
Regards
Sebastian
|
|
|
|
|
{
Process[] processes = Process.GetProcessesByName("notepad");
foreach (Process process in processes)
{
process.Kill();
}
}
modified on Thursday, May 13, 2010 1:08 AM
|
|
|
|
|
Use Process.GetProcessByName().
Or If you want to play it more safely, use Process.GetProcessById() method. To obtain the PIDs for the processes you want to end, get a list of all the processes running on your system using Process.GetProcesses(). Then manually traverse the list and find the PID of the processes you want to end, and then end them from there.
[Edit]Have a look at the process class and find out what it can do.[^][/Edit]
BTW, please answer this time, what are you building, and do you work for some company?
Excuse me for buttin' in, but I'm interrupt driven.
|
|
|
|
|
Hi,
what you could do is to monitor all the processes started while your app is running (look at the System.Diagnostics-namespace). If your app closes you can send a close to all the processes (or just do a hard "end process").
Regards
Sebastian
|
|
|
|
|
can u just send me example codes?
|
|
|
|
|
|
Now its working fine....
now everything is getting closed..but am getting the shutdown window also after giving this code
Process[] processlist = Process.GetProcesses("Avinash");
foreach (Process theprocess in processlist)
{
theprocess.CloseMainWindow();
}
i dont want to get that shutdown window...?
|
|
|
|
|
Hi Sandhya,
The reason you're getting that shutdown window is that the GetProcesses method gets a list of all running processes on the local computer or the machine name specified as an argument, and this list includes explorer as well. So when you call CloseMainWindow(), the close signal is being sent to all running programs including explorer as well. You should do like given below:
Process[] processlist = Process.GetProcessesByName("Notepad");
foreach (Process theprocess in processlist)
{
theprocess.CloseMainWindow();
}
All the best
Excuse me for buttin' in, but I'm interrupt driven.
|
|
|
|
|
In this case only notepad had got closed and rest others are there only..
(Explorer,MyComputer.,etc...)
|
|
|
|