|
I am using this
string sql = "UPDATE employees SET (Firstname) = ('" + newempTextBox.Text.ToString() + "') Where EmployeeID = ('" + empNamecomboBox.Text.ToString() + "')";
that could be completely incorrect.
So basically I want to set the firstname to the users entered text in the new form, where they have selected a name from the drop down in the previous form (class).
Thank you for such a quick response.
Sianny
|
|
|
|
|
Yes, this is a disaster.
First of all, if you're in another method, then the string you want is going to be what you passed in, not the exact same code which references a control that doesn't exist on this page.
Second, your code is completely insecure, and your database is compromised. You need to read up on SQL injections. Except, you say you've been programming for 2 months, so unless this is a class assignment ( which doesn't sound likely ), you should not be working on this at all.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
One way of doing .
Make a property in your combobox class and access your selecteditem through that property
|
|
|
|
|
But, the combobox is in another form....
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
private DataSet GetLoginDataSetXML()
{
string ConnectionString=GetConnectionString();
OleDbConnection OleDbconSource = new OleDbConnection(ConnectionString);
OleDbCommand OleDbcmdSource = new OleDbCommand();
OleDbcmdSource.Connection = OleDbconSource;
OleDbcmdSource.CommandType = CommandType.Text;
OleDbcmdSource.CommandText = "SELECT * FROM [Contacts$]";
OleDbadpSource.SelectCommand = OleDbcmdSource;
OleDbadpSource.UpdateCommand = OleDbcmdSource;
DataSet dsSource = new DataSet();
OleDbadpSource .Fill(dsSource);
//code to modify data in dataset here
OleDbadpSource.Update(dsSource);
dsSource.Tables[0].Rows[2].ItemArray[0] = "ns1:sinkName";
dsSource.Tables[0].Rows[2].ItemArray[0] = "CRRHistoricalForecast:sinkName";
TRYING TO CHANGE "ns1:sinkName" to "CRRHistorical:sinkName" BUT NOTHING IS HAPPENING
return dsSource;
|
|
|
|
|
Hi.
I have 2 webcams connected, they are from different providers, (a Genius NB and another cam).
My application must be able to capure both cams, so, I have 2 picture box and I'm using the API function capGetDriverDescription to get the descripions of the cams as the following code shows:
public static Device[] GetAllDevices()<br />
{<br />
String dName = "".PadRight(100);<br />
String dVersion = "".PadRight(100);<br />
<br />
for (short i = 0; i < 10; i++)<br />
{<br />
if (capGetDriverDescriptionA(i, ref dName, 100, ref dVersion, 100))<br />
{<br />
Device d = new Device(i);<br />
d.Name = dName.Trim();<br />
d.Version = dVersion.Trim();<br />
<br />
devices.Add(d); <br />
}<br />
<br />
dName = "".PadRight(100);<br />
dVersion = "".PadRight(100);<br />
}<br />
<br />
return (Device[])devices.ToArray(typeof(Device));<br />
}
This is code is from an article from here, CP.
The problem is, that this code only get the description of 1 cam, I don't know why but capGetDriverDescriptionA always return true one time.
Both cams works well, even there's a program called SKIN distributed by my Genius cam that can shows both devices and you can select which one to use. I don't how this program does that.
But I need to show the video of 2 web cams at the same time. Which API could help me?
Thank you.
Demian.
"I have always wished that my computer would be as easy to use as my
telephone. My wish has come true. I no longer know how to use my telephone."
-Bjarne Stroustrup, computer science professor, designer of C++
programming language (1950- )
|
|
|
|
|
Hi guys,
In my programme, I have a scenario where I have a particular image displayed through a picturebox. When I try to delete the picture through the code, it gives an exception saying that it is accessed by another programme.
I tried using the PictureBox.Dispose() method and PictureBox.Image=null methods before the deletion code runs, to solve this.
But, neither worked.
What's wrong here?
Regards,
A
|
|
|
|
|
The file is still being held open from when you opened the file. How did you open it ? Do you call Dispose on the image itself ? Disposing of the picturebox doesn't help, and setting the image to null does not call Dispose on it.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Well, I tried using dispose() on the picturebox.
I am displaying the image in the following way.
pictureBox.Image = System.Drawing.Image.FromFile(path);
How can I remove it from being held open?
|
|
|
|
|
I have a datagridview that I can rows using the down error and enterkey. I have DataGridView.Focus() firing after my method to addrows. The focus is on the proper cell but the cell is not active to type in. Does any have any suggestions on how to make the cell active?
|
|
|
|
|
you can select a cell with set the Selected property of that cell to true
like
this.dataGridView1[0, 0].Selected=true;
hope the post would be useful
good luck
|
|
|
|
|
Hello everyone!
I'm working on an application that converts hex data to decimal. Essentially what I do is send a command to an attached device via serial port and it spits back data to me.
The attached device spits data back in hex format and what I need to do is do a bit by bit comparision and convert some specific data to decimal format so I can do some calculations.
I'm at the point where the application I wrote spits this out:
55 55 FF AA 91 30 43 30 30 30 30 36 33 38 37 36 45 42 35 45 34 38 34 39 34 FF
The above data is just a sample. What I need to do is convert the data to decimal. The device that sends the data sends it back in asci format and i pass the data from a byte array into a function that converts it to hex digits.
What classes would I need to use to convert the data into decimal format? I have the initial data read into a byte array.
Sorry wasn't brief but I wanted to be as specific as possible
|
|
|
|
|
Int32.Parse(String, NumberStyles) First parameter is the string you want to convert to int. Use second parameter to specify that the string can be representation of hex number
|
|
|
|
|
Oh great thanks. I have tried that and the application crashes at runtime. So I ran the debugger and it says input string was not in correct format
//here is the method I created for this action
public int processArray(string data)
{
return Int32.Parse(data, NumberStyles.Integer);
}
here is where I call the method
string convertedS
convertedS = System.Text.Encoding.ASCII.GetString(buffer);
convert.processArray(convertedS);
maybe I'm doing something wrong from the very begining... Using .net 2.0 is it possible to read the data in the buffer I created for the serial port straight into a char array?
|
|
|
|
|
David Amyotte wrote: return Int32.Parse(data, NumberStyles.Integer);
Yes, it will produce an error because you are telling the compiler that the string is representation of number but in reality it is representation of HEX number so you should specify NumberStyles.HexNumber
|
|
|
|
|
You could convert the bytes directly using System.BitConverter.ToIntXX. Using a BinaryReader and a MemoryStream might be more convenient as you dont need to keep track of the array index.
|
|
|
|
|
thanks for your help so far.
What I'm doing so far is writing the data in the buffer into a Byte array then converting it to stringbuilder and the output so far is:
55 55 FF AA 91 30 43 30 30 30 30 36 33 38 37 36 45 42 35 45 34 38 34 39 34 FF
what I need to do is find an easy way to extract this data:
36 33 38 37 36 45 42 35 45 34 and convert it to decimal so I can do some calculations on the data. I'm new to .net so I figured this would be a good training exercise for me
Regards
|
|
|
|
|
It depends on the format of the data, you will need to look it up or work it out.
36 could be a byte
36 33 could be short
36 33 38 37 could be an int/float
36 33 38 37 36 45 42 35 could be a long/double
...
...
Example if 36 33 38 37 36 45 42 35 45 34 consits of 5 shorts:
byte[] data = {0x36, 0x33, 0x38, 0x37, 0x36, 0x45, 0x42, 0x35, 0x45, 0x34};
BinaryReader r = new BinaryReader(new MemoryStream(data));
for (int i = 0; i < 5; i++)
Console.WriteLine(r.ReadInt16());
|
|
|
|
|
In my old c++ days, I would use my old function below;
BOOL IsValidFilename(const char *szFilename)<br />
{<br />
<br />
if ( (!szFilename) || (!strlen(szFilename)) )<br />
return (FALSE);<br />
<br />
if ( (strchr(szFilename, '.')) || (strchr(szFilename, '\\')) ||<br />
(strchr(szFilename, '/')) || (strchr(szFilename, ':')) ||<br />
(strchr(szFilename, '<')) || (strchr(szFilename, '>')) ||<br />
(strchr(szFilename, '*')) || (strchr(szFilename, '?')) ||<br />
(strchr(szFilename, '|')) || (strchr(szFilename, '\"')) )<br />
return (FALSE);<br />
<br />
return (TRUE);<br />
}
I thought there might be a cleaner way to test a string before I used it for a file name.
Programmer
Glenn Earl Graham
Austin, TX
|
|
|
|
|
Maybe slightly cleaner. The
Path.GetInvalidFileNameChars should give you an array of invalid chars, which you can iterate and check
IndexOf in your candidate file name.
"Once in Africa I lost the corkscrew and we were forced to live off food and water for weeks." - Ernest Hemingway
My New Blog
|
|
|
|
|
Thanks here is the final code it works perfectly...
bool IsValidFilename(String ^fileName)
{
if ( String::IsNullOrEmpty( fileName ) == true )
return false;
array<Char>^ invalidFileChar = System::IO::Path::GetInvalidFileNameChars();
for each ( Char ^i in invalidFileChar )
{
if ( fileName->Contains(String::Format("{0}", i)) )
{
String ^tmp = String::Format(L" '{0}' is invalid in a file name.\n", i);
System::Windows::Forms::MessageBox::Show(gcnew String(tmp),gcnew String(L"Warning"),
MessageBoxButtons::OK);
return false;
}
}
return true;
}
Programmer
Glenn Earl Graham
Austin, TX
|
|
|
|
|
That doesn't look like C# to me.
|
|
|
|
|
String.IndexOfAny() seems appropriate here.
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
I'd just try it and catch the exception if any.
Let the OS/framework determine validity; it knows best.
|
|
|
|
|
But if its speed you want, catching the exception may not be the best solution.
Phil
|
|
|
|