C#SQL从表到C#提取日期的数据 [英] C# SQL taking out date's data from table to C#

查看:77
本文介绍了C#SQL从表到C#提取日期的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

SqlCommand cmd = new SqlCommand("SELECT * FROM [t_memsch] where [m_memcode]='" + m_memcode_input.Text + "'", conn);
                SqlDataAdapter sda1 = new SqlDataAdapter(cmd);
                DataTable ds1 = new DataTable();


                sda1.Fill(ds1);                

                try
                {   
                    //int temp = ds1.Rows.Count

                    decimal[,] allowance = new decimal[31,6]; //[day, session]

                    for (int row = 0; row < 31; row++)
                    {
                        for (int col = 0; col < 6; col++)
                        {
                            allowance[row, col] = 0;
                        }
                    }

                    for(int temp = ds1.Rows.Count; temp > 0; temp--)
                    {
                        temp--;
                        string date1 = ds1.Rows[temp]["m_schdate"].ToString();
                        temp++;

                        if (chk_date(date1, conn))
                        {
                            MessageBox.Show(date1);

                            if (chk_late(date1, conn))
                            {
                                MessageBox.Show("Good Boy!!");
                                
                                //int day = (int)cmd.ExecuteScalar();

                                allowance[28,3] = 30;
                                allowance[29, 1] = 12.7M;
                            }
                            else 
                            {
                                MessageBox.Show("Late! No pay.");
                                allowance[28,3] = 0;
                            }



我的表[t_memsch]中有一个列调用"t_scantime",并且t_scantime的格式为"12-31-2011 10:30:00"

现在,我只想将"t_scantime"中的日期插入到我的数组的天列中-allowance [day,session],有人可以给我一些帮助或想法吗?
P.S.想在"MessageBox.Show("Good Boy !!");"下执行插入语句这条线.

pleaseeeee.



There is a column call "t_scantime" in my table [t_memsch], and the format of t_scantime is "12-31-2011 10:30:00"

Now i want to insert the day only from "t_scantime" into my array''s day column - allowance[day,session], may anyone please give me some helps or idea?
P.S. wanna do the insert statement under "MessageBox.Show("Good Boy!!");" this line.

pleaseeeee.

推荐答案

string dttime = "12-31-2011 10:30:00";
            DateTime dt = Convert.ToDateTime(dttime);
            dttime = dt.Day.ToString();


请按照以下代码更改代码

Please change your code as per below code

Datetime date1 = convert.toDate(ds1.Rows[temp]["m_schdate"].ToString());
temp++;
if (chk_date(date1.tostring(), conn))
{
MessageBox.Show(date1.tostring());
if (chk_late(date1.tostring(), conn))
{

int day = date1.day;
allowance[28,3] = 30;
allowance[29, 1] = 12.7M;
}
else
{
MessageBox.Show("Late! No pay.");
allowance[28,3] = 0;
}



希望这会有所帮助.



Hope this will help.


这篇关于C#SQL从表到C#提取日期的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆