gpt4 book ai didi

vb.net - mscorlib.dll-DateTime中发生“System.FormatException”

转载 作者:行者123 更新时间:2023-12-03 08:52:55 24 4
gpt4 key购买 nike

同时出现以下故障排除提示...
“在将字符串转换为DateTime时,在将每个变量放入DateTime对象之前,分析String以获取数据”

我不知道为什么我的程序试图将其转换为DateTime?
我的访问数据库(已连接)严格是autoNumbers,Numbers和Short Text。

Dim objConnection As New OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source= InfoSystem.accdb")
Dim objAdminDA As New OleDb.OleDbDataAdapter("Select *from tblStudents", objConnection)
Dim objAdminCB As New OleDb.OleDbCommandBuilder(objAdminDA)
Dim objDataSet As New DataSet()

Private Sub frmAdmin_Load(sender As Object, e As EventArgs) Handles MyBase.Load

'Clears DataSet of any existing data
objDataSet.Clear()
'Fills schema - adds table structure information to DataSet
objAdminDA.FillSchema(objDataSet, SchemaType.Source, "tblStudents")
'Fills DataSet with info from the DataAdapter
objAdminDA.Fill(objDataSet, "tblStudents")
'Fill the DataSet with info from the Admin table
objAdminDA.FillSchema(objDataSet, SchemaType.Source, "tblStudents")
objAdminDA.Fill(objDataSet, "tblStudents")

Dim objRow As DataRow
objRow = objDataSet.Tables("tblStudents").Rows.Find("StudentNo")

txtAdminID2.Text = objRow.Item("StudentName")
txtAdminName2.Text = objRow.Item("AdminName")
txtDept2.Text = objRow.Item("Department")
txtTitle2.Text = objRow.Item("Title")

以下代码在以前的形式上消除了该问题,但似乎无法在此处进行处理。 (用TextBox代替ComboBox)。第一次在VB.net中使用数据库。
Dim objRow As DataRow
objRow = objDataSet.Tables("tblAdmins").Rows.Find(cboxAdminID.SelectedItem.ToString)
txtAdminName.Text = objRow.Item("AdminName")
txtDept.Text = objRow.Item("Department")
txtTitle.Text = objRow.Item("Title")

最佳答案

我将更改您的代码,因为您两次填充了数据集:

Dim objConnection As New OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source= InfoSystem.accdb")
Dim objAdminDA As New OleDb.OleDbDataAdapter("Select * from tblStudents", objConnection)
Dim objAdminCB As New OleDb.OleDbCommandBuilder(objAdminDA)
Dim objDataSet As New DataSet()

Private Sub frmAdmin_Load(sender As Object, e As EventArgs) Handles MyBase.Load

'Clears DataSet of any existing data
objDataSet.Clear()
'Fills DataSet with info from the DataAdapter
objAdminDA.Fill(objDataSet, "tblStudents")

' Get the row with the matching StudentNo
Dim objRow As DataRow
objRow = objDataSet.Tables("tblStudents").Rows.Find("StudentNo")

If objRow.count = 1 Then
txtAdminID2.Text = objRow.Item("StudentName").ToString
txtAdminName2.Text = objRow.Item("AdminName").ToString
txtDept2.Text = objRow.Item("Department").ToString
txtTitle2.Text = objRow.Item("Title").ToString
End-if

关于vb.net - mscorlib.dll-DateTime中发生“System.FormatException”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36149917/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com