|
Hello.
more detail:
I have a datagridview and i written save code for it ,but when i change the fied of datagridview Rows for test my save code,after i chenge field(immediately)and i press Eter key ,that row i chenged it be removed from datagridview,before i press save button .So i cann't save the changes.
But if i change the last row of datagridview this row not remove ,and i can save it exactly.
I do not know why other rows after change to remove.?
this is my save code:
private void myBindingNavigatorSaveItem_Click(object sender, EventArgs e)
{
SqlConnection objconnection = new SqlConnection(myconnection_string);
int i, idj, tedad, ghimat;
for (i = 0; i < myDataGridView.RowCount; i++)
{
idj = int.Parse((myDataGridView.Rows[i].Cells[0].Value).ToString());
tedad = int.Parse((myDataGridView.Rows[i].Cells[1].Value).ToString());
SqlCommand mycommand = new SqlCommand("UPDATE table1 SET tedad = @tedad WHERE (fid=@fid AND idj = @idj AND tedad ='0')", objconnection);
mycommand.Parameters.AddWithValue("@fid", fid);
mycommand.Parameters.AddWithValue("@idj", idj);
mycommand.Parameters.AddWithValue("@tedad", tedad);
objconnection.Open();
mycommand.ExecuteNonQuery();
objconnection.Close();
}
}
|
|
|
|
|
I have these two applications, one of which sends a screenshot image to the other. This works smoothly on most PCs, however some (older) PCs start receiving a lot of zeros after reading some of the data. How can I ensure that all the data being sent, is read? I don't know if this is a timeout issue, or what?
(I have found some solutions, such as WriteByte / ReadByte, but I need it to perform quite fast too, if possible)
The methods are as follows:
Sending:
if (nsStream.CanWrite)
nsStream.Write(bUp, 0, bUp.Length);
nsStream.Flush();
int x = 0;
while (nsStream.DataAvailable && x < dataReadWait)
{
x++;
}
return true;
Receiving:
if (nsStream.CanRead)
nsStream.Read(bDown, 0, bDown.Length);
nsStream.Flush();
return bDown;
At this point, it is worth saying that the Sender prior to sending the actual image, sends the length of the image (which is assigned to bDown), that is why data is read until the length of bDown...
Any help is so greatly appreciated!
|
|
|
|
|
I have sql (sql server 2005) table which is having StartDate and EndDate datetime columns.
<code>StartDate value inserting as 2009-08-11 00:00:00.000,
EndDate value inserting as 2009-08-11 23:59:00.000 (End of the day).</code>
This DB Server is located at london.
in my winforms(2.0) appliction i have typed dataset, is having same table schema.
Typeddatasset StartDate and EndDate DateTimeMode property set to UnspecifiedLocal.
i am populating this dataset with SP. SP is functioning properly.
returned data i am binding to DataGridView. when its biinding to datagridview,
<code>StartDate is showing as '8/11/2009 4:30 AM' instead of '8/11/2009 12:00 AM' and
EndDate is showing as '8/12/2009 4:29 AM' instead of '8/11/2009 11:59 PM'</code>
it seems problem is with databinding to dataset.
any sounds?
Ramana
modified on Wednesday, August 12, 2009 4:15 AM
|
|
|
|
|
Ramana. G.V wrote: This DB Server is located at london.
Where are you? I would guess it's just a time zone issue, that it's adjusting for your local time zone. Some very smart people worked very hard to make it work that way and now you say you want it the other way?
|
|
|
|
|
yes, if you have any other way to do. please help me
Ramana
|
|
|
|
|
I thought I had my Regular Expression working just fine, but then I found a weakness...
First off, I'm trying to parse a command line, so a Regex may not be the best tool, but it's so close! (And it's fine for testing purposes anyway.)
Given a command line like:
command param1 /options=( option1 , "option 2" , option3 ) "param 2"
I have no trouble getting most of this. Generally the worst part is that I have to get the contents of the options all together,
e.g. " option1 , "option 2" , option3 " , but that's not a big deal, I can parse it separately.
What I'm stumped by now, is if an option is in quotes and contains a right-parenthesis:
/options=( "(trouble)" )
The related piece of the Regex I'm using is:
"(?:/\\s*(?'Switch'\\w+)(?:\\s*=\\s*(?:(?:\"(?'Value'[^\"]*)\")|(?:\\((?'Value'[^\\)]*)\\)))|(?'Value'\\w+))?)"
I want "(trouble)" , I get "(trouble
Is there a way to get the Regex to recognize that the right-parenthesis is in quotes? I assume I need a balancing-group, but I can't wrap my head around it.
Edit:
I replaced ((?'Value'[^\\)]*) with (?'Value'(?:(?:\"[^\"]*\")|[^\\)]*?)*) and it seems to work.
modified on Wednesday, August 12, 2009 1:51 AM
|
|
|
|
|
hi,
I've some table of content or data. I've to show the content as table and charts in PDF using C#. Is there any possibility to display charts in PDF using some third party Dlls.
Pls let me know the solution.
Thanks in advance..........
-Ravi Vellanki
|
|
|
|
|
|
Hi all,
I need help from u all. I'm using tab controls in my program and added tab pages. Now my problem is i have to add menu items to that tab pages.Is it possible to add menus to tab pages.
If it is possible plz help me with some code...
Thanks in advance...
Elizabeth........
|
|
|
|
|
Hello All ,
I have design a factory class which will create the objects and send to the calling party. but i have small concern . Please see this code
public ElectricalDevice CreateDeviceType(int DeviceCode)
{
ElectricalDevice lobjDevice = null;
if (Convert.ToInt32(Helper.DeviceType.Fan) == DeviceCode)
{
lobjDevice = new Fan();
}
else if (Convert.ToInt32(Helper.DeviceType.Motor) == DeviceCode)
{
lobjDevice = new Motor();
}
else if (Convert.ToInt32(Helper.DeviceType.Tubelight) == DeviceCode)
{
lobjDevice = new Tubelight();
}
else
{
lobjDevice = new IronBox();
}
return lobjDevice;
}
This method is creating device and sending .
but my question is that if 2mrw i have to add some more device again i need to add more if else condition
So which pattern should i follow . Please give me some goood design links where can i have the video
|
|
|
|
|
What in Bob's name is that?! That looks totally bassackward to begin with.
If Helper.DeviceType is an enumeration then:
0) Why not send DeviceCode in as a Helper.DeviceType in the first place?
or 1) Cast the DeviceCode to Helper.DeviceType ? (Helper.DeviceType) DeviceCode
2) Why are you using Convert.ToInt32 when a simple cast will do? (int) Helper.DeviceType.Tubelight
2.0) Don't ever use Convert , it's needless.
3) Then you can use a switch instead of a bunch of freakin' if s.
switch ( DeviceCode )
{
case Helper.DeviceType.Fan : ...
}
or
switch ( (Helper.DeviceType) DeviceCode )
{
case Helper.DeviceType.Fan : ...
}
At least then your code will be readable and you can start looking for a better solution.
It appears you have a lot to learn about C# and just basic programming, I really hope you don't actually get paid to write code like this.
|
|
|
|
|
Hello ,
even if u are going for switch also . if 2mrw any device added then again u have to write obne more case statement ...
So that does not solve my problem
|
|
|
|
|
jpk420 wrote: that does not solve my problem
Indeed, which is part of why the Abstract Factory design pattern was defined. So, let's step back, what exactly are you trying to do?
Where does the DeviceCode come from?
|
|
|
|
|
Hello,
new to encryption.
however i am using the following partial code to encrypt and decrypt and it works....
<br />
<br />
<br />
byte[] encrypted = encryptStringToBytes_AES(txtMessage.Text, myRijndael.Key, myRijndael.IV);<br />
<br />
<br />
<br />
string decipheredText = decryptStringFromBytes_AES(encrypted, myRijndael.Key, myRijndael.IV);<br />
<br />
so this is an MSDN example and it works!!! i get the same thing if i DONT manipulate the byte[] any.
now the fun parts....
i try to do this
<br />
<br />
byte[] encrypted = encryptStringToBytes_AES(txtMessage.Text, myRijndael.Key, myRijndael.IV);<br />
<br />
<br />
string ciphertext = Encoding.UTF8.GetString(encrypted);<br />
<br />
byte[] cipher = Convert.FromBase64String(ciphertext);<br />
<br />
<br />
<br />
string decipheredText = decryptStringFromBytes_AES(cipher, myRijndael.Key, myRijndael.IV);<br />
<br />
<br />
<br />
as you can see i added 2 extra lines, and encoded to get back to a string. then converted to base 64 to get back to a byte []. YES i transmit the data in between those two lines but i made it simple to troubleshoot. this DOES NOT work..... i have tried diff encodings like UTF8 etc.
help!!
10 million dollars to the one who gets it working hahaha
thanks!
modified on Tuesday, August 11, 2009 11:32 PM
|
|
|
|
|
This is non-sense. You have an encrypted string in a byte array.
1. There is no guarantee that such byte array represents a string, yet you call Encoding.XXX.GetString() on it.
2. You have no guarantee that the result only contains characters from a limited set (the 64 characters acceptable in a Base64 string), yet you call Convert.FromBase64String() on the string.
Of course this does not work. There are two reasons it does not have to work.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
ahhhhh i seee what you are saying... hmmmmm
i need to send the byte[] over a streamwriter.....
|
|
|
|
|
i get the 10 million dollars!!!!!!!!!!
i solved it!!!!!
this is like the most common problem in cryptography on the NET!!!
heres the code fix:
basically this fixes problems with you cant convert from base64string
<br />
<br />
<br />
byte[] encrypted = encryptStringToBytes_AES(txtMessage.Text, myRijndael.Key, myRijndael.IV);<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
char[] base64data = new char[(int)(Math.Ceiling((double)encrypted.Length / 3) * 4)];<br />
<br />
Convert.ToBase64CharArray(encrypted, 0, encrypted.Length, base64data, 0);<br />
<br />
string ciphertext = new String(base64data);<br />
<br />
byte[] cipher = Convert.FromBase64String(ciphertext);<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
string decipheredText = decryptStringFromBytes_AES(cipher, myRijndael.Key, myRijndael.IV);<br />
<br />
chatbox.Text = decipheredText;<br />
<br />
<br />
the good conversions are in the middle between the spaces.
it works!!!!
tnx for all the help
|
|
|
|
|
|
try something like this:
using System.Drawing.Drawing2D;
private bool clearImage = false;
protected override void OnPaint(PaintEventArgs e)
{
if (this.clearImage)
{
using (Pen clearPen = new Pen(this.BackColor))
{
e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
e.Graphics.DrawEllipse(clearPen, 100, 100, 2, 2);
this.clearImage = false;
}
}
else
{
e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
e.Graphics.DrawEllipse(Pens.Red, 100, 100, 2, 2);
}
}
then your button click event
this.clearImage = true;
this.Refresh();
Hope this helps.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
|
hi
what is the best way for open connection to database ?
1.open in form1 - and close and open again in form2 ?
2.open in form1 as static - and use it for all form's (stay open all the time) ?
3.after I clossing the connection is it good to do - Connection.dispose() ?
I work on C#, and connect to sqlCE, Windows mobile 2005
thank's in addvance
|
|
|
|
|
I prefer method one. SQL server has connection pooling anyway, so it's likely to get re-used behind the scenes. And it clearly separates the functionality of the two forms, so one doesn't rely on another
Between the idea
And the reality
Between the motion
And the act
Falls the Shadow
|
|
|
|
|
Unless totally unavoidable, don't use option 2) (open all the time), considered very naughty.
Go for option 1) when you can.
As far as 3) is concerned try to do it like this:
using (SqlConnection myConnection = new SqlConnection(.....))
{
myConnection.Open();
}
by doing so you avoid having to worry about Dispose() and Close().
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
I use a static class for the DAL and close the connection after each operation.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
But when do you connect?
Generally I instantiate my DAL in Main, the DAL instantiates the connection and connects.
Then I can pass a reference to the DAL to the constructor of any Form that needs it.
Each method in the DAL opens and closes the connection as necessary.
using ( MyDAL dal = new MyDal ( ... ) )
{
S.W.F.A.Run ( new Form1 ( dal ) ) ;
S.W.F.A.Run ( new Form2 ( dal ) ) ;
...
}
A form (or other application) shouldn't know about the database at all.
|
|
|
|