|
I'm sorry, but that doesn't make any sense as a question. I am sure that English is not your native language, but please try to give more detail on what the problem is, so that we can help. It may be worth describing it is small words in your native language and then using Google Translate to get it into English.
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
|
|
|
|
|
Sorry - but what are you talking about?
The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it.
My latest tip/trick
|
|
|
|
|
Try here[^]
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
you question is not clear. Please clarify.
|
|
|
|
|
do you mean, how to implement IDictionary ?
|
|
|
|
|
I want to update Some Value to Marked Number Value in MarkedNumber Column
I Want to know where's the error in this code
public void UpdateMessageToIncludeMarkedNumber()
{
#region Compare to Insert Marked Number With Matching Message into Table in Database.
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "update VopMessage_tbl set MarkedNumber=@MarkedNumber where Byte24=@Byte24 and Byte4=@Byte4";
cmd.Connection = con;
for (int t = 0; t < Set10bytesMessage.Count; t++)
{
MarkedNumber mNumber = (MarkedNumber)Set10bytesMessage[t];
for (int f = 0; f < Set30bytesMessage.Count; f++)
{
VopMessage vms = (VopMessage)Set30bytesMessage[f];
if (mNumber.Byte4 == vms.Byte24 & mNumber.Byte5 == vms.Byte4)
{
cmd.Parameters.AddWithValue("@Byte24", vms.Byte24);
cmd.Parameters.AddWithValue("@Byte4", vms.Byte4);
string All2BytesOfTwoMarkedNumber = mNumber.Byte4 + mNumber.Byte5;
cmd.Parameters.AddWithValue("@MarkedNumber", All2BytesOfTwoMarkedNumber);
}
else
{
}
}
}
con.Open();
cmd.ExecuteNonQuery();
con.Close();
#endregion
}
|
|
|
|
|
You are only processing the last item in in Set30bytesMessage for the last item in Set10bytesMessage , if at all???
You repeatedly add the parameters in the the loop, so each parameter is potentially added more than once. Without knowing exactly what you are doing it is hard to tell but I'd hazard a guess and say you need to do this:
- The you should add the parameters before the loop
- The values of the parameters should be set inside the loop
- The
ExecuteNonQuery should happen inside the loop for each item
Is that any help? Some clue about what is going wrong/ what you expect would be good!
|
|
|
|
|
Here's the Error
The variable name '@Byte24' has already been declared. Variable names must be unique within a query batch or stored procedure.
If I put : cmd.Parameters.AddWithValue("@Byte24", vms.Byte24);
cmd.Parameters.AddWithValue("@Byte4", vms.Byte4);
out side loop , from where can I get the value of vms.Byte24
|
|
|
|
|
See my previous reply, my guess was correct!
public void UpdateMessageToIncludeMarkedNumber()
{ SqlCommand cmd = new SqlCommand();
for (int t = 0; t < Set10bytesMessage.Count; t++)
{
MarkedNumber mNumber = (MarkedNumber)Set10bytesMessage[t];
for (int f = 0; f < Set30bytesMessage.Count; f++)
{
VopMessage vms = (VopMessage)Set30bytesMessage[f];
if (mNumber.Byte4 == vms.Byte24 & mNumber.Byte5 == vms.Byte4)
{
<big>
}
}
}
con.Open();
<big>
cmd.ExecuteNonQuery();
con.Close();
}
}
|
|
|
|
|
+5 on the original answer, but wouldn't clearing the Parameters collection more efficient? He'd be reusing them for the same task, which seems logical.
Just curious
I are Troll
|
|
|
|
|
Eddy Vluggen wrote: wouldn't clearing the Parameters collection more efficient?
After clearing the collection you would need to add the parameters again, creating more objects each time the loop runs. It is far more efficient to update the existing parameters.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Mark Nischalke wrote: After clearing the collection you would need to add the parameters again, creating more objects each time the loop runs.
Yup, true. Thanks for the explanation
I are Troll
|
|
|
|
|
You Should Now that from this loop If the condition
if (mNumber.Byte4 == vms.Byte24 && mNumber.Byte5 == vms.Byte4)
not occur , no repeat will done and also you will should now that the condition will occur only one time.
|
|
|
|
|
The error you are getting indicates that Parameters are being added more that once so your loop is being executed multiple times.
Add the parameters when creating the SqlCommand
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "update VopMessage_tbl set MarkedNumber=@MarkedNumber where Byte24=@Byte24 and Byte4=@Byte4";
cmd.Connection = con;
cmd.Parameters.Add("@Byte24", ...);
cmd.Parameters.Add("@Byte4", ...);
cmd.Parameters.Add("@MarkedNumber", ...);
Then inside the loop update the values each time
cmd.Parameters["@Byte24"] = vms.Byte24;
cmd.Parameters["@Byte4"] = vms.Byte4;
string All2BytesOfTwoMarkedNumber = mNumber.Byte4 + mNumber.Byte5;
cmd.Parameters["@MarkedNumber"] = All2BytesOfTwoMarkedNumber;
cmd.ExecuteNonQuery();
You should also make use of the using statement
using(SqlCommand cmd = new SqlCommand("update VopMessage_tbl set MarkedNumber=@MarkedNumber where Byte24=@Byte24 and Byte4=@Byte4", conn)
{
}
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Thanks very Much ...It Work Correctly.
|
|
|
|
|
What error message are you getting?
Jack of all trades ~ Master of none.
|
|
|
|
|
You could easily find the error if you just used the tools that come with Visual Studio - namely, the debugger.
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997
|
|
|
|
|
Hi
I have discovered an issue using Type.GetProperties on a COM object when running under .NET 3.5 & .NET 4.0.
The following code uses the Microsoft Scripting Runtime COM object as an example - it has the same behaviour with any COM object I have tried. Under .NET 3.5, it correctly returns an array containing one property (the Drives property). Under .NET 4.0, it returns no properties.
Scripting.FileSystemObject fs = new Scripting.FileSystemObject();
Type t = fs.GetType();
PropertyInfo[] props = t.GetProperties();
Type.GetProperties seems to work correctly on .NET objects and only seems a problem with COM objects.
I have some generic code that sets property values by using a string variable as the name that works in .NET 3.5 and now fails in .NET 4.0.
I know that I can upgrade the code to use the dynamic type in .NET 4.0 to do this BUT why is this not backwards compatible or at least documented in some way that is easy to find?
Kind regards
Andy
|
|
|
|
|
Sorry to state the obvious, but since Microsoft are the providers of this software, I believe they are best qualified to answer your question.
I must get a clever new signature for 2011.
|
|
|
|
|
Sorry but that part of the posting with a question mark was really a rhetorical question and I could not report it to MS as the forums appeared to be down when I tried. I was hoping that someone may have experienced the same issue and had some constructive advice.
My comment that I could always use the new dynamic type seems wide of the mark and it doesn't help me at all. For the purposes of the project I'm working on, I need to be able to call a property by its name since I am mapping some data between two applications and the mapping details are stored in XML configuration files.
I need to use .NET 4.0 since I am developing an application to be certified for Dynamics CRM 5 and this looks like it will only allow .NET 4.0. The other application is a legacy application that only has a COM interface so I'm a little stuck at the moment.
Regards
Andy
|
|
|
|
|
This is the example they give on the MSDN site:
PropertyInfo[] myPropertyInfo;
myPropertyInfo = Type.GetType("System.Type").GetProperties();
Slightly different from yous, but I'd give it a try.
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997
|
|
|
|
|
Hi John,
I think you will find that
string x = "";<br />
x.GetType().GetProperties()
is exactly the same as
Type.GetType("System.String").GetProperties()
Thanks for taking the time to answer though
Regards
Andy
|
|
|
|
|
Yeah, I know, but stranger things have happened in .Net.
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997
|
|
|
|
|
Is there a way to still sort the Class View by type (without grouping by type) and have the enums that are defined within a class only display within that class like members do?
|
|
|
|
|
i want to copy a tex from texbox and paste it another one in my form
i copy it with that code
Clipboard.SetText(textBox1.SelectedText);
and paste it with that
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
if ((e.Modifiers == Keys.Control)&&(e.KeyCode == Keys.V))
textBox2.Text = Clipboard.GetText();
}
but the problem is it pastes selceted text two times but when i try like that
(e.Modifiers == Keys.Control)
it pastes one time
what should i do now ?
vemedya.com
|
|
|
|