|
i setted the keydownpreview true of the form and create a keydownpreview_event of the form, but the event does not trigger.
|
|
|
|
|
Hi.i want to craete a class that will read data from database and display it on the texboxes.but it can not display it.so i did this
try
{
SqlCommand cmdSearch = new SqlCommand();
cmdSearch.Connection = conn;
cmdSearch.CommandText = "SELECT Name,Surname FROM Users WHERE UserName =@UserName";
SqlParameter Nam = new SqlParameter();
Nam.ParameterName = "@Name";
Nam.Direction = System.Data.ParameterDirection.Output;
Nam.Value = Name;
cmdSearch.Parameters.Add(Nam);
SqlParameter Sur = new SqlParameter();
Sur.ParameterName="@Surname";
Sur.Direction = System.Data.ParameterDirection.Output;
Sur.Value = Surname;
cmdSearch.Parameters.Add(Sur);
SqlParameter Use = new SqlParameter("@UserName",System.Data.SqlDbType.VarChar,50,UserName);
Use.Value = UserName;
cmdSearch.Parameters.Add(Use);
SqlParameter Lev = new SqlParameter();
Lev.ParameterName="@Level";
Lev.Direction = System.Data.ParameterDirection.Output;
Lev.Value = Surname;
cmdSearch.Parameters.Add(Lev);
SqlDataReader dr =cmdSearch.ExecuteReader();
if(dr.Read() == true)
{
MessageBox.Show("Record found");
}
else
{
MessageBox.Show("Record not found");
}
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
conn.Close();
|
|
|
|
|
A question ends with a ?
BTW, never, ever, never ever, do if(dr.Read() == true) unless it is just a typo.
A man said to the universe:
"Sir I exist!"
"However," replied the Universe, "The fact has not created in me A sense of obligation."
-- Stephen Crane
|
|
|
|
|
Ennis Ray Lynch, Jr. wrote: BTW, never, ever, never ever, do if(dr.Read() == true) unless it is just a typo.
Personally, I hate this syntax would use if(dr.Read()) - im interested why you think this should "never ever" be done though
|
|
|
|
|
Because you will get flamed by coworkers
Really it doesn't bother me too mucb but everyone else around here seems to pitch a fit about it. Of course, with a data reader it should be while(dr.Read()) :p as well
A man said to the universe:
"Sir I exist!"
"However," replied the Universe, "The fact has not created in me A sense of obligation."
-- Stephen Crane
|
|
|
|
|
Ennis Ray Lynch, Jr. wrote: it should be while(dr.Read()) :p as well
Only if you expect the datareader to have more than 1 row. If I wanted to ensure that I only ever read the first row, then if(dr.Read()) would be a necessity!
|
|
|
|
|
If you are using if(dr.Read()) to ensure only one row your query is bad.
A man said to the universe:
"Sir I exist!"
"However," replied the Universe, "The fact has not created in me A sense of obligation."
-- Stephen Crane
|
|
|
|
|
hi all,
i have a datagridview with 2 columns. (1 is readonly and the other can be edited)
i want to restrict users just to type characters from 0 to 9 and . (dot).
how can i check this during editing ?
in which event should i place this code:
Regex regex = new Regex("^[0-9-.]*$");
if (regex.IsMatch(txtprice.Text))
{
// Type is Correct!
}
ps: and this code is a textbox's check. how should write selectedcell index instead of txtprice.Text ?
thanks in advance,
bye.
|
|
|
|
|
Mehmet Fatih Akbulut wrote: i want to restrict users just to type characters from 0 to 9 and . (dot).
Unfortunately you can not do that. While this GenericDataGridView[^] article can solve your problem.
Regards.
_____________________________
Success is not something to wait for, its something to work for.
|
|
|
|
|
Handle the DataGridView.CellValidating event, and use the argument's ColumnIndex property to check to make sure its within the row(or rows) you want to validate to have that format. Use Decmial.TryParse and use the System.Globalization.NumberStyles.* modifiers to only include numberic and decimal points. If that fails, either inform the user or set the cell's value to 0.
|
|
|
|
|
Hi All,
I need to redirect command line output to a text file.
here is my code test.exe that takes test as a parametr.
Process p = new Process();
p.StartInfo.FileName = "C:\\test.exe";
p.StartInfo.Arguments = "Test";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardInput = false;
p.StartInfo.RedirectStandardError = false;
p.StartInfo.CreateNoWindow = true;
p.Start();
Console.WriteLine("output");
string output = p.StandardOutput.ReadToEnd();
Console.WriteLine(output);
p.WaitForExit(1000);
p.Close();
Issues is that I dont get the redirected output. test.exe is an app that writes all the printer events to the output window and can only be stopped with a break ctrl C.
Let me know what goin wrong. How do i redirct the output.I have also used > text.txt but in vain.
newdev
|
|
|
|
|
Process.StandardOutput,Process.StandardInput,Process.StandardError are streams with the data you need.
Process.OutputDataReceived is one of the events to tell you when data is written.
A man said to the universe:
"Sir I exist!"
"However," replied the Universe, "The fact has not created in me A sense of obligation."
-- Stephen Crane
|
|
|
|
|
Hi..Thanks for the reply. Can anyone give a sample code that will work fine..
|
|
|
|
|
Hi.
Was wonder if it is possible to take an argument at the point of installation. That I can do, the question actually being if that value the user enters can contain spaces. Works wonderfull aslong as you enter single word values.
Thanx in advance
He who laughs last is a bit on the slow side
|
|
|
|
|
Hi
I work with Framework 2.0 (c#).
I do not know how to dynamicaly change ForeColor of a row in DataGridView depending on value of one column in grid which changes dynamically too.
When I tried to use DataGridView.CellFormatting event only cell where the value is changed has the right forecolor. However other have the old one.
After selecting and deselecting other cells in the row they have right color.
AlternatingStyle is not good because there are more than two kind of colors.
Which event do I have to use and which method call in order to refresh a whole row?
Before (in Framework 1.1) I did it by creating columns inheriting from my own class where method paint was overriden. However I would like to use new features in F 2.0.
Thanks
Ela
|
|
|
|
|
e_LA wrote: When I tried to use DataGridView.CellFormatting event only cell where the value is changed has the right forecolor
I think you're close. You can get the rowindex from this event and change the cells in the row.
only two letters away from being an asset
|
|
|
|
|
Sorry but I do not understand. Move to others cells?
|
|
|
|
|
I did something like that in formattingCellEvent
myDataGridView.Rows[e.RowIndex].Cells[5].Style.ForeColor = e.CellStyle.ForeColor;
Just fifth cell for example ....
and now it works
....very strange
|
|
|
|
|
It doesn't work if I stay in the same row (I do not change the row) - for example by pressing TAB not ENTER.
I think I should return to the previous version with overriding Paint event in custom type column
|
|
|
|
|
I don't understand what you are trying to do and what you are doing. Maybe a code snippet would be helpful. Once you change the color of a cell it doesn't matter what else you do.
only two letters away from being an asset
|
|
|
|
|
Hi all.
I'm working with Observer pattern in C#. I want to show the modifications in all clients windows conected. The only way y have found to do this is using a timmer which refresh the clients windows. In this timmer I do the call to the update.
Some one knows another way to do this with no timmer??
Thanks.
_mistika_
|
|
|
|
|
Why don't you have the client windows subscribe to an event that tells them when a change has been made, the client window's event handler will then update themselves.
|
|
|
|
|
2-way Databinding will show changes in the fields when the underlying data changes.
|
|
|
|
|
Hi,
We already have a windows service set up to write to binary file for "our" custom events. Need to translate this binary file into comma delimited text file - how would we go about doing that? Can we just some built in VS2005 functions?
any ideas/thoughts much appreciated.
Thank you for your time.
|
|
|
|
|
Read the binary file, convert the data into text base on whatever format specification that your system employ, write the file into the CSV file.
Or
Write both binary and CSV during your "normal operation".
|
|
|
|