在Excel和VB.Net之间input数据

创build一个应用程序来运行jar头查询。 查询使用Excel工作表的forms使用最终用户提供的input数据。 事先知道所需的input列数据types,我创build了types化的数据表对象。 如何从Excel导入时validation提供的数据是否正确input?

我的查询似乎将数字数据转换为string,以适应我的types的数据表。 我不想要这个,我想在这种情况下抛出一个错误。 对于包含多种types数据的input列,查询也会将less数types转换为空值。 这样可以禁止types表中的空值, 除非查询经常返回几个额外的空值行,即使在正确types的input数据表中也是如此。

下面的代码…如何validationexcel数据严格遵循架构?

Dim strInputData As String = "Desktop\testfile.xlsx" Dim strCon As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & strInputData & ";Extended Properties=""Excel 12.0 Xml;HDR=YES"";" Dim connection As New OleDb.OleDbConnection(strCon) Dim command As New OleDb.OleDbCommand command.Connection = connection Dim inputDataSQL As String = "Select [Member ID], [Carrier ID] from [Sheet1$]" command.CommandText = inputDataSQL command.CommandTimeout = 0 Dim inputData As New typedDataTable connection.Open() Try inputData.Load(command.ExecuteReader(CommandBehavior.CloseConnection)) Catch ex1 As System.Data.ConstraintException connection.Close() MsgBox("Invalid data. Please use template or contact developer.") GoTo [Exit] End Try