|
You could load the Xml file into a XmlDocument and use the its SelectNodes method to select the nodes you want. The method returns a collection of selected nodes over which you can iterate and retrieve the wanted values.
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
Hello gurus,
I'd like to know how I can get connected to the default instance of SQL Server with user login?
Where can I find a code snipet that shows how to do that with Windows authentication and SQL Server authentication?
Best regards.
Fred.
There is no spoon.
|
|
|
|
|
bouli wrote: I'd like to know how I can get connected to the default instance of SQL Server with user login?
By just specifying the machine name, without any instance part.
You can find lots of examples of connection strings for SQL Server here: http://www.connectionstrings.com/?carrier=sqlserver[^]
|
|
|
|
|
Also, if you just want some examples related to your local databases you could look at the connection string that is located in the properties dialog when you select a database server in the server viewer section of VS2005.
Aaron
_____________________________________________________________________
Our developers never release
code. Rather, it tends to escape, pillaging the countryside all around.
The Enlightenment Project (paraphrased comment)
Visit Me at GISDevCafe
|
|
|
|
|
This should get you started.
try<br />
{<br />
SqlConnection connection = new SqlConnection("server=localhost; database=yourdb; user=yourusername; password=yourpassword);<br />
connection.Open();<br />
}<br />
catch (SQLExcepton SqlE)<br />
{<br />
//Do you exception handling here<br />
connection.Close();<br />
}
Remember, you need to include the System.Data.Sql namespace for this
|
|
|
|
|
Hi experts!
I trying to write a program to read a byte[] from IrDA port.
The IrDA device is onboard (laptop), and in the BIOS this device uses: COM2, but, using the component SerialPort from .NET 2.0, using the COM2 and invoking the method Open() i retrieve a exception: COM2 doesn't exist.
This device is correctly installed and working with windows. I tried add a new COM port, using same IRQ from IrDA, but, this conflicted with IrDA device
How i can use my IrDA device in .NET 2.0?
Thanks in advance
|
|
|
|
|
How do you open the port?
|
|
|
|
|
I add a SerialPort component in the form, with name: serialPort1
and in the code:
serialPort1.PortName = "COM2";<br />
serialPort1.Open();<br />
The exception says the com2 port doesn't exist.
It´s wrong?
|
|
|
|
|
No i think that's ok..
Take a look at the Infrared Device in the DeviceManager.. maybe you need to configure it when you want to use it as comPort under windows
|
|
|
|
|
Does Hyperterminal see the port? If not then neither can .NET. Another possibility would have been if the com port used by the IrDA does not begin with COM, there's a retarded check in the Open method which checks to see if the port name begins with COM! At least MS are going to remove this check for the next release thanks to my comment :->
|
|
|
|
|
No, the COM2 don´t appears in the HyperTerminal, but, the IrDA device to file transfer with windows works perfect.
How i know whats name of my port?
|
|
|
|
|
If Hyperterminal can't see it then it's almost guaranteed that it's not operating as a standard Windows COM port. It's probably got a proprietry driver, check through the documentation to see if there's an SDK or something like it available to talk to the com port.
Alternatively see if you can find out which library or executable is being used for the transferring and look with depends.exe to see which library it's calling to talk to the IrDA port.
|
|
|
|
|
First of all it would be a good idea to check all ports on your computer first. I use it like this.
public enum PortAvailabillity
{
Available, InUse
}
public static Dictionary<int, PortAvailabillity> GetPorts()
{
string[] availablePorts = SerialPort.GetPortNames();
Dictionary<int, PortAvailabillity> portStatus = new Dictionary<int,PortAvailabillity>();
foreach (string s in availablePorts)
{
int number = int.Parse(s[s.Length - 1].ToString());
try
{
SerialPort p = new SerialPort(s);
if (!p.IsOpen)
portStatus.Add(number, PortAvailabillity.Available);
else
portStatus.Add(number, PortAvailabillity.InUse);
}
catch (IOException err )
{
#if DEBUG
Console.WriteLine("Error getting port: " + err.ToString());
#endif
}
}
return portStatus;
}
Also you might want to set some more parameters when opening the port (baudrate and such). Always make sure no other program is using the port when you try this.
Standards are great! Everybody should have one!
|
|
|
|
|
Thanks! I try this, and, later i write the result.
|
|
|
|
|
I've extended the PictureBox control to create my own user control. Now I want to capture the OnMouseWheel . I've done this many times, and it's usually enough to override like this
protected override void OnMouseWheel(MouseEventArgs e) . Unfortunately the overidden method is never called when I turn my mousewheel. I've also tried tying the MouseWheel even to my own method. Weird enough, this isn't called either... Could this be related to the parent control the box is placed in? Any suggestions?
Standards are great! Everybody should have one!
|
|
|
|
|
You might try creating a user control that you know has the OnMouseWheel event enabled. Another option would be to inherit from the picturebox and override its WndProc with information related to the mouse wheel.
Regards,
Thomas Stockwell
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
Visit my homepage Oracle Studios[ ^]
|
|
|
|
|
The picture box should have this event enabled. I've tried the following and found it to be working: The form is placed within a SplitContainer control. Since I was guessing it might be the parent container that was the problem, I tried tying my method to SplitContainer.Panel1.MouseWheel event first. When this wasn't working, I tied it to SplitContainer.MouseWheel . This actually works. This seems very strange because I've always thought that events were passed from the toplevel container on to the back. The solution isn't very charming, since this means the control I made will have to be hooked differently to it's parent controls, depending on the type of parent it's placed In.
Overriding its WndProc seems like a good idea, it's just that I have no idea of how to do this. If you can give me a pointer that would be very welcome, it's almost weekend for me and I don't feel like starting it with leaving an annoying problem like this unsolved
Standards are great! Everybody should have one!
|
|
|
|
|
I know it's 4 years too late, but I ran across this post while looking for information on the Delta values in the MouseEventArgs passed to OnMouseWheel .
The reason controls like PictureBox don't fire that event is because it doesn't have focus. An easy fix should be to override OnMouseEnter and calling the control's Focus() method. You may also need to call your control's SetStyle method and give it ControlStyles.Selectable in it's contructor.
It's probably way too late, but I hope that helps anyway.
"Political correctness is a doctrine, fostered by a delusional, illogical minority, and rabidly promoted by an unscrupulous mainstream media, which holds forth the proposition that it is entirely possible to pick up a turd by the clean end" - Unknown
|
|
|
|
|
Was surprised to see a reply to a 4 year old question that I didn't remember I asked in my inbox .
Thanks for the answer. Perhaps the problem has been haunting my subconsciousness for 4 years and is finally at peace . More likely I found a way around it back then though. Still; others may find your answer very useful, thanks again.
Standards are great! Everybody should have one!
|
|
|
|
|
SqlCommand cm = new SqlCommand("select dashboardid from dashboardlogin where (loginname = 'hina') AND (loginpswd = 'shaikh')", conn);
int i = Convert.ToInt32(cm.ExecuteScalar());
i have this query working properly,but it gives dashboardid of only loginname=hina.
but i want dashboardid of that person who logs in the system(this code is on login form),whoever logs in the system,his dashboardid must be got in variable 'i'.
what must i do to change my query for such result?
thank you.
nekshan.
|
|
|
|
|
string strQuery="";
strQuery = "select dashboardid from dashboardlogin where (loginname = '" + txtLoginName.Text + "') AND (loginpswd = '" + txtPassword.Text + "')";
SqlCommand cm = new SqlCommand(strQuery, conn);
int i = Convert.ToInt32(cm.ExecuteScalar());
txtLoginName.Text and txtPassword.Text will be your text boxes from where you will take the user name and password. This is a simple solution but creating dynamic queries are prone to SQL Injection attacks. Use Stored procedures instead or use parameterized command object. Search msdn for more information.
"A good programmer is someone who looks both ways before crossing a one-way street." -- Doug Linder
coolestCoder
|
|
|
|
|
coolestCoder wrote: This is a simple solution but creating dynamic queries are prone to SQL Injection attacks. Use Stored procedures instead or use parameterized command object.
I'm curious why you didn't just do that in your example. It seems to me to be some what disingenuous to offer a solution with known security problems then point out the problems when it would have been just as quick to write a version without those problems.
|
|
|
|
|
Nekshan wrote: but it gives dashboardid of only loginname=hina.
Duh....
Nekshan wrote: what must i do to change my query for such result?
First, don't delete your questions after they are answered.
Second, I would reiterate that the questions that you're asking, show that you need to learn some basics before tackling this project. I can see you've found that if you keep asking here, we wil write it all for you, but you will pay later for never learning a solid foundation to build on.
The obvious answer is to build a string that includes the login name and password, from the controls which were used to enter them. However, you'd do better to write a stored procedure , because this will help protect you from SQL injection attacks. A paramaterised query would be an easier way to try to protect yourself in this regard.
The highlighted words are for your help figuring out how to use google to find out more info.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Read the section "Parameterized Queries" of the following CP article: SQL Injection Attacks and Some Tips on How to Prevent Them[^]. The other sections of the article are also worth reading them.
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
Since you seem to have a history of deleting your original question, I've repoduced it here in full so that anyone else with a similar problem can see exactly what is going on.
Nekshan wrote: SqlCommand cm = new SqlCommand("select dashboardid from dashboardlogin where (loginname = 'hina') AND (loginpswd = 'shaikh')", conn);
int i = Convert.ToInt32(cm.ExecuteScalar());
i have this query working properly,but it gives dashboardid of only loginname=hina.
but i want dashboardid of that person who logs in the system(this code is on login form),whoever logs in the system,his dashboardid must be got in variable 'i'.
what must i do to change my query for such result?
thank you.
nekshan.
SqlCommand cm = new SqlCommand("SELECT dashboardid FROM dashboardlogin "+
"WHERE loginname = @loginname AND loginpwd = @password", conn);
cm.Parameters.Add("@loginname", theLoginName);
cm.Parameters.Add("@password", thePassword");
object rawId = cm.ExecuteScalar();
if (rawId == DBNull.Value)
{
// The login wasn't found - handle this
}
else
{
int id = (int)rawId;
// Do stuff with the id
}
|
|
|
|