- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个问题。每当我将数据从 DataGridView 保存到文本文件中时,日期的格式就会自动转换为日期和时间。它不应该是这样的,因为 datagridview 所基于的数据只是纯日期,但是当我将其传输到文本文件中时,它会自动添加时间。它看起来像这样:
246,4/20/2013 12:00:00 AM,01:00:00,p
如何删除日期附带的时间 (12:00:00 AM)?
这些是数据网格的代码:
Private Sub load_table()
sConnection = New MySqlConnection
sConnection.ConnectionString = "server=localhost;userid=root;password=;database=cph;Convert Zero Datetime=True"
Dim SDA As New MySqlDataAdapter
Dim sqlCommand As New MySqlCommand
Dim bSource As New BindingSource
Try
sConnection.Open()
Dim Query As String
Query = "select * from swipe_table"
sqlCommand = New MySqlCommand(Query, sConnection)
SDA.SelectCommand = sqlCommand
SDA.Fill(dbDataSet)
bSource.DataSource = dbDataSet
DataGridView1.DataSource = bSource
SDA.Update(dbDataSet)
sConnection.Close()
Catch ex As MySqlException
MessageBox.Show(ex.Message)
Finally
sConnection.Dispose()
End Try
End Sub
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
sConnection = New MySqlConnection
sConnection.ConnectionString = "server=localhost;userid=root;password=;database=cph;Convert Zero Datetime=True"
Dim SDA As New MySqlDataAdapter
Dim sqlCommand As New MySqlCommand
Dim bSource As New BindingSource
Try
sConnection.Open()
Dim Query As String
Query = "select * from swipe_table"
sqlCommand = New MySqlCommand(Query, sConnection)
SDA.SelectCommand = sqlCommand
SDA.Fill(dbDataSet)
bSource.DataSource = dbDataSet
DataGridView1.DataSource = bSource
SDA.Update(dbDataSet)
sConnection.Close()
Catch ex As MySqlException
MessageBox.Show(ex.Message)
Finally
sConnection.Dispose()
End Try
End Sub
这些代码用于保存到文本文件部分:
Private Sub Button4_Click(sender As System.Object, e As System.EventArgs) Handles Button4.Click
Dim filename As String = String.Empty
Dim sfd1 As New SaveFileDialog()
sfd1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*"
sfd1.FilterIndex = 2
sfd1.RestoreDirectory = True
sfd1.Title = "Save Text File"
If sfd1.ShowDialog() = DialogResult.OK Then
If sfd1.FileName = String.Empty Then
MsgBox("Please input filename")
Else
filename = sfd1.FileName.ToString
Saveto_TextFile(DataGridView1, filename)
End If
End If
End Sub
Sub Saveto_TextFile(ByVal dvList As DataGridView, ByVal filename As String)
Dim strDestinationFile As String = "" & filename & ".txt"
Dim tw As TextWriter = New StreamWriter(strDestinationFile)
Dim LineToWrite As String = String.Empty
Try
For _Row As Integer = 0 To DataGridView1.Rows.Count - 1
LineToWrite = String.Empty
For _Column As Integer = 0 To DataGridView1.Columns.Count - 1
If DataGridView1.Rows(_Row).Cells(_Column).Value IsNot Nothing Then
LineToWrite &= "," & DataGridView1.Rows(_Row).Cells(_Column).Value.ToString
Else
LineToWrite &= ","
End If
Next
LineToWrite = LineToWrite.Remove(0, 1) 'remove the first comma
tw.WriteLine(LineToWrite)
Next
tw.Flush()
tw.Close()
MessageBox.Show("Data Saved Successfully")
Catch ex As Exception
MessageBox.Show("An error occurred")
End Try
End Sub
最佳答案
检查单元格值的类型...
For _Column As Integer = 0 To DataGridView1.Columns.Count - 1
If DataGridView1.Rows(_Row).Cells(_Column).Value IsNot Nothing Then
If DataGridView1.Rows(_Row).Cells(_Column).Value.GetType Is GetType(Date) AndAlso CDate(DataGridView1.Rows(_Row).Cells(_Column).Value).TimeOfDay = New Date().TimeOfDay Then
LineToWrite &= "," & CDate(DataGridView1.Rows(_Row).Cells(_Column).Value).ToShortDateString
Else
LineToWrite &= "," & DataGridView1.Rows(_Row).Cells(_Column).Value.ToString
End If
Else
LineToWrite &= ","
End If
Next
关于mysql - 在 vb.net 上保存日期值时从 DataGridView 保存到文本文件问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24006284/
NHibernate version: 3.3.2. 我有一个包含多个操作的 NHibernate 事务。作为事务中的中间步骤之一,我尝试通过 Session.Save 插入一个具有自动增量 PK 的
请参阅我有一个具有多个值的 HashSet,该值可以包含例如 4141234567 、 4241234567 _0x10456790719 4141234567 _0x104567907907 和 _
我有一个 javafx 应用程序,我有一个主界面,我可以在其中设置我的舞台并启动该应用程序。我还有一个 Controller 类: public class Controller { @
我正在编写一个与 Web 服务集成的 iPhone 应用程序。我将从网络服务获取数据并用它填充表格 View 。我的问题:当用户滚动表格 View 时,我希望从 Web 服务动态加载更多数据并填充表格
我有以下结构: PreProd > Variables.tf 具有: variable "vms" { default = [ { "hostname" : "Monitor0
我下面有一个 Shiny 的应用程序,它显示绘图或表格。我对表格不感兴趣,我的问题只涉及 plotly 部分。当我使用此 javascript solution 在浏览器中打开应用程序时,我尝试下载该
我目前正在学习如何在 Java 中使用 Swing。将 JTextFields、JLabels 或 JButtons 添加到 JPanel 时,我通常用 4 行来完成,如下所示: gbc.gridx
我有一个名为 TabView 的自定义 UIView 类。每个 TabView 中都有 2 个标签以及一些其他元素。我使用界面生成器将这些标签添加到 TabView 中。在将 TabViews 作为
class A{ private List list; // getter setter public class B{ @command public void dele
当计时器达到零时,我试图从 Pane 中删除元素,更具体地说是标签和文本区域。但是,当计时器达到 0 并且我调用此方法时,我收到此异常。 Exception in thread "AWT-EventQ
使用 LINQ 时我应该从 WCF 服务返回什么?例如: var res = from q in context.cust select q; LINQ 遵循延迟执行,因此语句在运
我有一个计时器,可以在 GameScene.swift 文件中启动/重置,但是当应用程序在通话期间最小化或按下主页按钮时,它会继续运行。如何停止计时器并在应用程序再次处于事件状态时继续计时器? if
我有以下 Java 程序,但我不想在最后一个元素之后分配“,”,怎么办? String range = "400-450"; Integer startRange = null;
我正在使用 SAX 来解析一些 XML。在我的处理程序中 startElement()方法我正在尝试读取名为 xsi:type 的属性的值,例如: String type = attributes.g
我正在从事一个项目,该项目必须将数据从 Excel 文件导入和导出到数据库等。我必须从数据库获取数据,然后。但是如何根据 id、电话号码、用户名检查 excel 文件中的数据是否不重复。这是读取exc
我需要 Hook 程序的日志记录功能并获取它的日志记录参数,它使用 sqlite3_prepare_v2 -> sqlite3_bind_xxx -> sqlite3_step 函数。我想知道是否有可
您好,我正在尝试创建一个画笔,但我在使用 SelectObject 这行代码时遇到了问题: Brush_C = SelectObject(hdc_TS, hBrush); 错误是这样的: line 2
我正在尝试制作一个用户可以登录并将其用户数据保存到 mysql-db 的应用程序。我正在使用 PreferenceActivity 和 PreferenceFragment 来处理这个问题。通常这工作
我们使用自定义标签代码在 Google map 中添加带有标签的标记,还使用 MarkerCluster 库对标记进行聚类。 我们的问题是标记隐藏了,但标签仍然显示。我们需要修改http://go
我有一个包含 3 列的 CSV 文件;文本,整数,文本。当我导入这些时,所有数据都包含在双括号中。我不确定为什么。是否可以使用 COPY 在导入时删除这些内容?或者我应该导入为文本,然后使用 sele
我是一名优秀的程序员,十分优秀!