It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
Creating digital clock. I'm newbie to C#. My code look like that
timeLbl.Text = DateTime.Now.ToLongTimeString();
dateLbl.Text = DateTime.Now.ToLongDateString();
Here is, the result
http://content.screencast.com/users/TT13/folders/Jing/media/da6d1f65-bf5f-4735-97dc-70485112a998/2012-07-02_1826.png
I got some questions:
Can I change time's format to 24 Hour? how?
How to change date into digits only format (like dd/mm/yyyy) or this result but in exact language (I mean, words "Monday, July" in another language, which windows support, for ex Turkish)?
How to make window dynamically change it's width (depending on text
length)?
Please help me,to achieve these 3 things. Thx in advance
Ans 1:
timeLbl.Text = DateTime.Now.ToString("HH:mm:ss");
Will convert time to 24 hour format.
Ans 2:
dateLbl.Text = DateTime.Now.ToString("dd/MM/yyyy");
Will convert date format to 31/06/2012
More formats here
The first and second point where been answered, for the last point set SizeToContent="WidthAndHeight" on the window and the window will dynamically resize based on its content size. I assume ur working with wpf, else it doesnt works!
Related
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
It has soon been 12h of trying this and I can't get it to work. I have read all the threads I can find and nothing helps. I have tried to fiddle around with Excel Wrapper as well but it doesn't work. I'm new to C# and I'm trying to do a bullshit generator. What I am trying to do is reading a bunch of words from A1-A5, B1-B5 and C1-C5 in an .xlsx-file and putting them together in a textbox (I'm using Visual Studio) when clicking a button.
If anyone reads this and could give me a hint it would be much appreciated. Thanks in advance.
First you should pull the info from the xls doc to a collection (array, list, etc...)
The code for this should be easy to find online.
You are also going to need a random number generator:
Random rnd = new Random();
Then you are going to have the button click event select 2 random numbers, one for row and one for column, from your collection (2D array in this case):
int row_max = stuff[][].GetLength(0);
int col_max = stuff[][].GetLength(1);
int row = rnd.Next(0, row_max-1)
int col = rnd.Next(0, col_max-1); //between 0 and the number of columns
textbox1.text = textbox1.text + stuff[row][col].ToString();
This is indicative only, but all the parts of this can be easily googled.
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
I am developing a C# application, and I have a date column in SQL Server.
I am performing a query based on date, using DateTimePicker. I have changed the format of datetime picker to short, now it displays date as mm-dd-yyyy
Now while executing I get correct output from date 1-12 but as soon as I select 13 date I get error as
conversion failed when converting date/time from character string
I don't know what is happening!
I suspect you're using the formatted string from that DateTimePicker to build an SQL query on the fly via format strings or concatenation.
Don't do that.
Date/time string literals in SQL tend to use a sane format (i.e. ISO 8601) where the order of the parts differs. The fact that it blows up when you change a piece from 12 to 13 should give it away, actually.
An SqlCommand has parameters (you can insert in the query with #foo. Using those will ensure that everything gets passed in the right way and properly quoted:
using (SqlCommand c = connection.CreateCommand()) {
c.CommandText = "Select roll_number,name from Attendance_table where date=#date";
c.Parameters.AddWithValue("date", dateTimePicker1.Value);
using (var r = c.ExecuteReader()) {
...
}
}
(roughly – you should consult the documentation for proper usage, it's been a while that I wrote such things)
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I have a FlowDocument in which I need to insert many fragments of dynamic text at arbitrary positions.
For example, I need to place text "Hello" at x = 10, y = 15 and text "World" at x = 10, y = 20.
I'm currently doing this using Figure. I create a Run with the text, put it in a Paragraph, and put all that in a Figure. From there I can set it's VerticalOffset and HorizontalOffset. Then I place all the figures in a Paragraph which I add to the FlowDocument.
Everything was going OK (it was the simplest approach I could came up) until I had to place two or three fragments of text on the same line (at the same y but different x).
For some reason it's putting each Figure on a new line instead of putting them all in the same line, let me illustrate:
Expected:
text1 text2 text3
Actual:
text1 text2 text3
Does anybody know how to remove that line break between figures? If you have a better approach to this problem I'm open to suggestions too.
I ditched FlowDocument and went with XAML and used a Canvas... made my life much easier being able to place all text fields visually... much easier to maintain in the long run too.
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I want to have a variable name with a white space.
Am passing this collection to a gridview and i need the title to have a white space instead of an underscore
var registrationReport = (from r in BankMedEntity.Customers
select new {r.Id,Customer Type = r.CustomerType_Id });
Any idea on how i can accomplish that?
I need to have the title as "Customer Type" instead of "CustomerType_Id"
You cannot, c# does not allow spaces in variable names. They would be considered different words and the compiler will go "Ahh...What do you mean?"
Turn this to false
AutoGenerateColumns="True"
And add your own Bound columns to the Gridview. You will be able to give the columns whatever names you want
Unfortunately that is impossible; the compiler has no way of figuring out that the two separate words are actually part of the same variable name.
No space is allowed in variable name.
If you want the title of the gridview with no underscore, you should edit the girdview definition in .aspx file.
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
I'm having a problem altering the stock in my database. What I am looking to do is to minus the stock in my database by 1 when the button 'Reserve Item' is clicked on. So say the stock is sitting at 10. When I reserve an item I want the stock in the database to automatically decrease to 9.
Any ideas on how this can be achieved Using ASP.NET with C#?
Even shorter:
update stock_table
set stock_quantity = stock_quantity - 1
where stock_id = xxx
The SQL UPDATE statement
What you really want to do is something like this:
UPDATE stock_table
SET stock_quantity = (SELECT stock_quantity - 1 FROM stock_table WHERE stock_id = '#####')
WHERE stock_id = '#####'
'######' presents the id of your item (not sure if you are using int or varchar/text or guid).