通过Access 2000向DB2表存数据?VB.NET 2005适配Windows 10问题
Getting Your VS2005 VB.NET App Running on Windows 10 + Fixing That INSERT Statement
Let’s start with the driver headaches—since that’s the main blocker getting your app up and running on Windows 10:
- Legacy driver check: VS2005 dates back to the Windows XP/Vista era, so the drivers your linked table relies on might not be present or enabled by default on Windows 10. If you’re using ODBC, head to Control Panel > Administrative Tools > ODBC Data Sources (make sure to open the 32-bit version if your app is built as 32-bit—VS2005 defaults to 32-bit) and confirm the driver for your backend database exists. If it’s missing, grab the latest compatible driver from your database vendor (e.g., the ACE driver for Access, SQL Server Native Client for SQL Server).
- Compatibility mode hack: Right-click your app’s executable file, go to Properties > Compatibility, and check "Run this program in compatibility mode for"—pick Windows XP (Service Pack 3) or Windows Vista. This often fixes finicky legacy driver interactions that Windows 10’s stricter security settings block.
- Connection string tweak: Double-check your connection string uses the correct driver name for Windows 10. For example, if you were using the old Jet driver (
Microsoft.Jet.OLEDB.4.0), switch to the ACE driver (Microsoft.ACE.OLEDB.12.0) which is supported on modern Windows versions.
Now let’s fix that INSERT statement—driver issues can amplify data type mismatches, so let’s eliminate those risks:
Your current query:
INSERT INTO MY_DB_MY_LINKED_TABLE (FIELD1, FIELD2, FIELD3, FIELD4, TIMETOENTER) values ('Sometext', '2018', '1234567', '20/11/17', 3)
- Date field (FIELD4) red flag: Passing a string like
'20/11/17'for a date/time field is risky—system locale settings and driver differences can misinterpret the date (is that November 20th, 2017, or May 11th, 2017?). Use parameterized queries instead—they let the driver handle date conversion safely and avoid formatting errors. Here’s how to implement this in VB.NET:Dim insertSql As String = "INSERT INTO MY_DB_MY_LINKED_TABLE (FIELD1, FIELD2, FIELD3, FIELD4, TIMETOENTER) " & _ "VALUES (@Field1, @Field2, @Field3, @Field4, @TimeToEnter)" Using conn As New OleDbConnection(yourConnectionString) conn.Open() Using cmd As New OleDbCommand(insertSql, conn) ' Add parameters with explicitly defined types cmd.Parameters.Add("@Field1", OleDbType.VarChar).Value = "Sometext" cmd.Parameters.Add("@Field2", OleDbType.VarChar).Value = "2018" cmd.Parameters.Add("@Field3", OleDbType.VarChar).Value = "1234567" ' Parse the date with exact format to avoid locale confusion cmd.Parameters.Add("@Field4", OleDbType.Date).Value = DateTime.ParseExact("20/11/17", "dd/MM/yy", Nothing) cmd.Parameters.Add("@TimeToEnter", OleDbType.Integer).Value = 3 cmd.ExecuteNonQuery() End Using End Using - Bonus security win: Parameterized queries also prevent SQL injection, which is a good practice even for internal apps.
- Linked table name: Since you’re using underscores (no dots) in the table name, you don’t need to wrap it in brackets—your current syntax is perfectly valid here.
A few more quick troubleshooting tips:
- Run as administrator: Sometimes legacy drivers require elevated permissions to access system resources on Windows 10. Right-click the app and select "Run as administrator" to test this.
- Check Event Viewer for clues: If the app crashes or throws vague errors, look in Event Viewer > Windows Logs > Application—it’ll have detailed error messages about driver failures or database connection issues that can point you to the root cause.
内容的提问来源于stack exchange,提问作者Vlad
相关产品推荐
相关产品推荐

