Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 网格视图页面上没有时间显示_C#_.net_Sql Server - Fatal编程技术网

C# 网格视图页面上没有时间显示

C# 网格视图页面上没有时间显示,c#,.net,sql-server,C#,.net,Sql Server,我使用的是SQLServer2005,C.NET 我只想在我的网格视图页面上显示日期,当前它也显示时间。 我正在使用文件上载按钮单击功能恢复表中的日期。 在我的表中,我采用的加载日期列数据类型是DateTime。 表格列中的示例显示2010年10月19日12:00:00 AM 在我的网格视图页面上,我也得到了日期栏,比如10/19/2010 12:00:00 am 我想像2010年10月19日一样出现在我的网格上 string strDate = DateTime.Now.ToShortDate

我使用的是SQLServer2005,C.NET

我只想在我的网格视图页面上显示日期,当前它也显示时间。 我正在使用文件上载按钮单击功能恢复表中的日期。 在我的表中,我采用的加载日期列数据类型是DateTime。 表格列中的示例显示2010年10月19日12:00:00 AM

在我的网格视图页面上,我也得到了日期栏,比如10/19/2010 12:00:00 am

我想像2010年10月19日一样出现在我的网格上

string strDate = DateTime.Now.ToShortDateString();
cmd.Parameters.Add("@LoadDate", SqlDbType.DateTime).Value = strDate.ToString();
下面是我的代码。请任何人都可以帮助我如何删除我的网格视图页面上的时间

protected void btnUpload_Click(object sender, EventArgs e)
        {


            // Read the file and convert it to Byte Array
            string strClaimNumber = lblFileUploadCliamNumber.Text.ToUpper();
            string strDate = DateTime.Now.ToShortDateString();

            string strDescription = txtDescription.Text.ToString();
            string filePath = FileUpload1.PostedFile.FileName;
            string filename = Path.GetFileName(filePath);
            string ext = Path.GetExtension(filename);
            string contenttype = String.Empty;

            //Set the contenttype based on File Extension

            switch (ext)
            {
                case ".doc":
                    contenttype = "application/vnd.ms-word";
                    break;
                case ".docx":
                    contenttype = "application/vnd.ms-word";
                    break;
                case ".xls":
                    contenttype = "application/vnd.ms-excel";
                    break;
                case ".xlsx":
                    contenttype = "application/vnd.ms-excel";
                    break;
                case ".jpg":
                    contenttype = "image/jpg";
                    break;
                case ".png":
                    contenttype = "image/png";
                    break;
                case ".gif":
                    contenttype = "image/gif";
                    break;
                case ".pdf":
                    contenttype = "application/pdf";
                    break;

            }

            if (contenttype != String.Empty)
            {


                Stream fs = FileUpload1.PostedFile.InputStream;
                BinaryReader br = new BinaryReader(fs);
                Byte[] bytes = br.ReadBytes((Int32)fs.Length);


                //insert the file into database

                string strQuery = "insert into tblFiles(Name, ContentType, Data, Description, ClaimNumber, LoadDate)" +
                   " values (@Name, @ContentType, @Data, @Description, @ClaimNumber, @LoadDate)";
                SqlCommand cmd = new SqlCommand(strQuery);
                cmd.Parameters.Add("@Name", SqlDbType.VarChar).Value = filename;
                cmd.Parameters.Add("@ContentType", SqlDbType.VarChar).Value
                  = contenttype;
                cmd.Parameters.Add("@Data", SqlDbType.Binary).Value = bytes;
                cmd.Parameters.Add("@Description", SqlDbType.VarChar).Value = strDescription.ToString();
                cmd.Parameters.Add("@ClaimNumber", SqlDbType.NVarChar).Value = strClaimNumber.ToUpper();
                cmd.Parameters.Add("@LoadDate", SqlDbType.DateTime).Value = strDate.ToString();
                InsertUpdateData(cmd);
                lblMessage.ForeColor = System.Drawing.Color.Green;
                lblMessage.Text = "File Uploaded Successfully";
                GridView1.DataBind();
            }

            else
            {

                lblMessage.ForeColor = System.Drawing.Color.Red;
                lblMessage.Text = "File format not recognised." +
                  " Upload Word/PDF/Excel formats";

            }

        }

在gridview模板中尝试以下操作:

<asp:Label ID="lblDate" Text='<%# String.Format("{0:M/d/yyyy}", Eval("DateColumnName")) %>' runat="server" />

如果选择从数据库表中检索存储的日期并将其显示在Datagridview中,请使用下面提到的查询

Select Convert(Varchar(15),Datecolumn,1) from Tablename
上述查询将以05/09/13格式显示日期