English 中文(简体)
p与以下C#代码相混合,把零时间储存到q子服务器?
原标题:whats the pblm with the following c# code for storing date n time into sql server?

我试图将日期和时间储存在地板服务器上,但正出现错误。

    private void button1_Click(object sender, EventArgs e)
    {
        string d = DateTime.Now.ToShortDateString();
        string t = DateTime.Now.ToShortTimeString();
        cmd.CommandText = "insert into transaction values("+label9.Text+", "+d+" , "+t+" );";
        cmd.Connection = con;
        con.Open();
        int x= cmd.ExecuteNonQuery();
        MessageBox.Show("Attendance recorded succesfully");   
    }      

http://www.ohchr.org。 我将数据类型作为var仪服务器中的日期和时间领域。

问题回答

使用[交易]而不是交易

private void button1_Click(object sender, EventArgs e)
    {
        string timeString = "11/12/2009 13:30:00.000";
        IFormatProvider culture = new CultureInfo("en-US", true);
        DateTime dateVal = DateTime.ParseExact(timeString, "dd/MM/yyyy HH:mm:ss.fff", culture);
        cmd.CommandText = "insert into transaction values(" + label9.Text + ", " + dateVal + " );";
        cmd.Connection = con;
        con.Open();
        int x = cmd.ExecuteNonQuery();
        MessageBox.Show("Attendance recorded successfully");
    }
private void button1_Click(object sender, EventArgs e)
    {
        string d = DateTime.Now.ToString("dd/MM/yyyy");
        string t = DateTime.Now.ToString("hh:mm:ss tt");
        cmd.CommandText = "insert into transaction values("+label9.Text+", "+d+" , "+t+" );";
        cmd.Connection = con;
        con.Open();
        int x= cmd.ExecuteNonQuery();
        MessageBox.Show("Attendance recorded succesfully");   
    }     

第二,你也可以尝试使用KetDate(GetDate) 职能:在无错误的情况下插入日期和时间。

仅限日期:

 SELECT DATEADD(dd, 0, DATEDIFF(dd, 0, GETDATE()))

第一部分:

  • 不得变形;和

  • 无需考虑当地情况

时间:

SELECT LTRIM(RIGHT(CONVERT(VARCHAR(20), GETDATE(), 100), 7))

如果有人能够帮助利用“Convert”和“当地”获得时间/时间。





相关问题
Export tables from SQL Server to be imported to Oracle 10g

I m trying to export some tables from SQL Server 2005 and then create those tables and populate them in Oracle. I have about 10 tables, varying from 4 columns up to 25. I m not using any constraints/...

SQL server: Can NT accounts be mapped to SQL server accounts

In our database we have an SQL server account that has the correct roles to access some of the databases. We are now switching to windows authentication and I was wondering if we can create a NT user ...

SQL Server 2000, ADO 2.8, VB6

How to determine if a Transaction is active i.e. before issuing Begin Transaction I want to ensure that no previous transaction are open.. the platform is VB6, MS-SQL Server 2000 and ADO 2.8

热门标签