|
On my PC, DateTime.Now.ToShortTimeString() shows the date as 11:42 AM. If you have something similar, it will fail when you parse it as hh:mm:ss.
What happens when you debug it and watch the values? Do the two labels really show the date in hh:mm:ss format? Either change the format string, or use DateTime.Now when you do the subtraction.
Cheers,
Vikram. (Proud to have finally cracked a CCC!) Recent activities:
TV series: Friends, season 10
Books: Fooled by Randomness, by Nassim Nicholas Taleb. Carpe Diem.
|
|
|
|
|
Values in label6 is like 11:18:17 and Values of label7 is 11:18:17, the value of label7 is constant.
|
|
|
|
|
DateTime dt1 = DateTime.ParseExact("11:15:00", "hh:mm:ss", new DateTimeFormatInfo());
DateTime dt2 = DateTime.ParseExact("11:20:00", "hh:mm:ss", new DateTimeFormatInfo());
TimeSpan ts1 = dt1.Subtract(dt2);
Console.WriteLine(ts1.ToString());
Works for me.
Do you get the error when you create dt1 or dt2?
Cheers,
Vikram. (Proud to have finally cracked a CCC!) Recent activities:
TV series: Friends, season 10
Books: Fooled by Randomness, by Nassim Nicholas Taleb. Carpe Diem.
|
|
|
|
|
yes i get the error when value insert in dt1 or dt2.
|
|
|
|
|
Hi,
what is all this???
have you read the DataTimeFormatInfo documentation[^]?
are you aware that ToShortTimeString() uses the regional settings of your PC?
and new DateTimeFormatInfo() does not?
and why store text twice in label6?
and why parse text from label7 as you know quite well what is in there?
and why going for a negative time span?
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.
|
|
|
|
|
Sir
i want to calculate difference b/w time
u give me some suggestion.
|
|
|
|
|
Hi,
so you choose to ignore my 7 questions? and want something from me? take this:
private DateTime started;
public Form1() {
InitializeComponent();
started=DateTime.Now;
timer.Tick += new EventHandler(timer1_Tick);
timer.Interval = (1000) * (1);
timer.Start();
}
private void timer1_Tick(object sender, EventArgs e) {
DateTime now=DateTime.Now;
label6.Text = "It is now "+now.ToString("HH:mm:ss");
double seconds=now.Subtract(started).TotalSeconds;
label7.Text = "which is "+seconds+" seconds since this form started.";
}
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.
|
|
|
|
|
Luc, I appreciate your intent, but spoonfeeding creates rather than solves problems.
Cheers,
Vikram. (Proud to have finally cracked a CCC!) Recent activities:
TV series: Friends, season 10
Books: Fooled by Randomness, by Nassim Nicholas Taleb. Carpe Diem.
|
|
|
|
|
I agree, and I seldom do spoon feed. I usually provide pointers, and/or my go study a book[^] advice.
In this case, there was too much wrong IMO, so I decided to provide a reasonable starting point.
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.
|
|
|
|
|
Hi,
Can someone give me some straight example on how to view such an Office Document '.doc' in a Web Browser Control.
You're help is really appreciated .
Kind Regards,
Erson
|
|
|
|
|
See this[^] article.
It's not necessary to be so stupid, either, but people manage it. - Christian Graus, 2009 AD
|
|
|
|
|
Thank you for this. I just happened to be in the right place at the right time lol
Regards,
Jason Pezzimenti.
|
|
|
|
|
If a text file is opened and given to print for a printer installed on the PC, how to catch the data that is going to printer before it gets printed.
|
|
|
|
|
hi evry1!
i needed to create a form in which i hav to browse and open mdb files ---> i did this part usin oprnfile dialogue!
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog oDlg = new OpenFileDialog();
oDlg.Title = "Select MDB";
oDlg.Filter = "MDB (*.Mdb)|*.mdb";
oDlg.RestoreDirectory = true;
string dir = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
oDlg.InitialDirectory = dir;
DialogResult result = oDlg.ShowDialog();
if (result == DialogResult.OK)
{
textBox1.Text = oDlg.FileName.ToString();
}
}
this is my code so far!!!
now i need to make 3 list boxes!!
1st one to display the table names of the db!
2nd to to display field names when clicked on table name!!!
3rd to display attributes on fiels on clickin on it!
v can edit the attribute values and on clickin of save button it should update the database!!!
pls help
|
|
|
|
|
|
if u could b specific it wud b gr8
|
|
|
|
|
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog oDlg = new OpenFileDialog();
oDlg.Title =
"Select MDB";
oDlg.Filter =
"MDB (*.Mdb)|*.mdb";
oDlg.RestoreDirectory =
true;
string dir = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
oDlg.InitialDirectory = dir;
DialogResult result = oDlg.ShowDialog();
if (result == DialogResult.OK)
{
textBox1.Text = oDlg.FileName.ToString();
}
string strFileName = oDlg.FileName.ToString();
OleDbConnection cn = new OleDbConnection();
DataTable schemaTable;
cn.ConnectionString =
"Provider=Microsoft.Jet.OLEDB.4.0;Mode=Share Deny None;Data Source="+strFileName;
cn.Open();
schemaTable = cn.GetOleDbSchemaTable(
OleDbSchemaGuid.Tables,
new Object[] { null, null, null, "TABLE" });
//List the table name from each row in the schema table.
for (int i = 0; i < schemaTable.Rows.Count; i++)
{
strTableName = schemaTable.Rows[i].ItemArray[2].ToString();
listBox1.Items.Add(strTableName);
}
//Explicitly close - don't wait on garbage collection.
cn.Close();
}
this is my code so far!!!
now i need to make 3 list boxes!!
1st one to display the table names of the db<-----done till here!!!!
2nd to to display field names when clicked on table name!!!---> to b done!
3rd to display attributes on fiels on clickin on it!!!---> to b done!v can edit the attribute values and on clickin of save button it should update the database!!!
|
|
|
|
|
i need to make 3 list boxes!!
1st one to display the table names of the db<-----done till here!!!!
2nd to display field names when clicked on table name!!!<-----done till here!!!!
3rd to display attributes of the fields on clickin on it!!!---> to b done!
4.v shud b able to edit the attribute values and on clickin of save button it should update the database!!! ---> to b done!
this is my code so far!!!
.
.
public partial class Form1 : Form
{
private OleDbConnection cn = new OleDbConnection();
private DataTable schemaTable;
public Form1()
{
InitializeComponent();
cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Mode=Share Deny None;Data Source=";
}
private void button1_Click(object sender, EventArgs e)
{
cn.Close();
cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Mode=Share Deny None;Data Source=";
listBox1.Items.Clear();
listBox2.Items.Clear();
OpenFileDialog oDlg = new OpenFileDialog();
string strFileName = "";
oDlg.Title = "Select MDB";
oDlg.Filter = "MDB (*.Mdb)|*.mdb";
oDlg.RestoreDirectory = true;
string dir = Environment.GetFolderPath(Environment.SpecialFolder.MyComputer);
oDlg.InitialDirectory = dir;
DialogResult result = oDlg.ShowDialog();
if (result == DialogResult.OK)
{
strFileName = oDlg.FileName.ToString();
textBox1.Text = strFileName;
}
cn.ConnectionString += strFileName;
cn.Open();
schemaTable = cn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables,
new Object[] { null, null, null, "TABLE" });
//List the table name from each row in the schema table.
for (int i = 0; i < schemaTable.Rows.Count; i++)
{
string strTableName = schemaTable.Rows[i].ItemArray[2].ToString();
listBox1.Items.Add(strTableName);
}
}
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
listBox2.Items.Clear();
string strTableName = listBox1.SelectedItem.ToString();
schemaTable = cn.GetOleDbSchemaTable(OleDbSchemaGuid.Columns,
new Object[] { null, null, strTableName, null });
//List the column name from each row in the schema table.
for (int i = 0; i < schemaTable.Rows.Count; i++)
{
string strColName = schemaTable.Rows[i].ItemArray[3].ToString();
listBox2.Items.Add(strColName);
}
}
private void button3_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void listBox2_SelectedIndexChanged(object sender, EventArgs e)
{
listBox3.Items.Clear();
string strTableName = listBox1.SelectedItem.ToString();
schemaTable = cn.GetOleDbSchemaTable(OleDbSchemaGuid.Columns,
new Object[] { null, null, strTableName, null });
//List the column name from each row in the schema table.
for (int i = 0; i < schemaTable.Rows.Count; i++)
{
string strColItm = schemaTable.Rows[i].ItemArray[4].ToString();
listBox2.Items.Add(strColItm);
}
}
}
|
|
|
|
|
Hi everyone,
1- How can we rename Column Header Text in DataGridView? Is that possible to make the header editable?
2- Can we show or hide Columns in DataGridView?
3- How can we swap column positions if column are in numbers and we have to horizontally scroll to access different columns?
Thanks.
Good Day.
|
|
|
|
|
1 column[1].caption = "this col"
1a I am pretty sure a header can not be made editable, that would make it like any other row. You could work around this with a dummy row
2 column[1].visible = false
3 set the ordinal position of the column (I have never done this so I am not sure)
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
hello
i made one login form after username and password type
when login button enter i need to fire login button event
i used the acceptbutton property in form but in this property i need to enter two times but here i need one enter button press to go fire
please give me the solution
|
|
|
|
|
Hi, nobody is going to just give you the solution. Can you post the code for the login button that you have?
Excellence is doing ordinary things extraordinarily well.
|
|
|
|
|
Set AcceptButton Property of form to the login button
Reg
Deep
Happy Coding
|
|
|
|
|
i set the acceptbutton property the login button
but i need two times enter to go
|
|
|
|
|
In that case, something in your code or another control is consuming the first Enter, as it should just work with one press. Without seeing the code it's impossible to diagnose what's causing the problem.
This works for me.
using System;
using System.Drawing;
using System.Windows.Forms;
public partial class FormLogIn : Form
{
TextBox textBoxUserName;
TextBox textBoxPassword;
Button buttonLogIn;
public FormLogIn()
{
InitializeComponent();
SuspendLayout();
textBoxUserName = new TextBox();
textBoxUserName.Location = new Point(12, 12);
textBoxPassword = new TextBox();
textBoxPassword.Location = new Point(12, 38);
textBoxPassword.UseSystemPasswordChar = true;
buttonLogIn = new Button();
buttonLogIn.Text = "Log In";
buttonLogIn.Location = new Point(12, 64);
buttonLogIn.Click += buttonLogIn_Click;
MinimizeBox = false;
MaximizeBox = false;
FormBorderStyle = FormBorderStyle.FixedSingle;
StartPosition = FormStartPosition.CenterScreen;
Size = new Size(132, 132);
Text = "Log In";
AcceptButton = buttonLogIn;
Controls.AddRange(new Control[] { textBoxUserName, textBoxPassword, buttonLogIn });
ResumeLayout(false);
}
void buttonLogIn_Click(object sender, EventArgs e)
{
Close();
}
}
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|