问题描述
嗨朋友们,
我试图通过访问表中的参数添加数值,我收到上述消息。什么是解决方案,我尝试如下:
我尝试过的事情:
Sub DataTrans()
Dbconnection.Open()
MasterReader = MasterCmd.ExecuteReader()
试试
MasterReader.Read()
IntArr(0)=(MasterReader(Sap_No))
IntArr(1)=(MasterReader(DesigIndex))
IntArr(2)=(MasterReader) (CurrYear))
StrArr(0)=(MasterReader(CPF_No.ToString))
StrArr(1)= (MasterReader(Name.ToString))
StrArr(2)=(MasterReader(指定.ToString))
LvMasterCmd.CommandText =INSERT INTO LeaveMaster(CPF_No,Name,Designation,MNT,YR,LeaveStatus,CurrYear,Sap_No,DesigIndex)&
VALUES(@ CPF_No,@ Name,@ Designation,@ MNT,@ YR,@ LeaveStatus,CurrYear,@ Sap_No,@ DesigIndex);
尝试
LvMasterCmd.Parameters.AddWithValue(@ Sap_No,IntArr(0))
LvMasterCmd.Parameters.AddWithValue(@ DesigIndex,IntArr(1))
LvMasterCmd.Parameters.AddWithValue(@ CurrYear ,IntArr(2))
LvMasterCmd.Parameters.AddWithValue(@ CPF_No,StrArr(0).ToString)
LvMasterCmd。 Parameters.AddWithValue(@ Name,StrArr(1).ToString)
LvMasterCmd.Parameters.AddWithValue(@ Designation,StrArr(2).ToString)
LvMasterCmd.Parameters.AddWithValue(@ MNT,CmbMonth.Text)
LvMasterCmd.Parameters.AddWithValue(@ YR,CmbYear.Text)
LvMasterCmd.Parameters.AddWithValue(@ LeaveStatus,N)
LvMasterCmd.Exe cuteNonQuery()
LvMasterCmd.Parameters.Clear()
Catch ex As Exception
MessageBox.Show(ex.Message)
结束尝试
结束时
Catch ex As Exception
MessageBox.Show(ex.Message)
结束尝试
Dbconnection.Close()
结束Sub
Hi friends,
I am trying to add numerical value through parameter in access table, I receive aforesaid message. what will be the solution, I have tried as follows:
What I have tried:
Sub DataTrans()
Dbconnection.Open()
MasterReader = MasterCmd.ExecuteReader()
Try
While MasterReader.Read()
IntArr(0) = (MasterReader("Sap_No"))
IntArr(1) = (MasterReader("DesigIndex"))
IntArr(2) = (MasterReader("CurrYear"))
StrArr(0) = (MasterReader("CPF_No".ToString))
StrArr(1) = (MasterReader("Name".ToString))
StrArr(2) = (MasterReader("Designation".ToString))
LvMasterCmd.CommandText = "INSERT INTO LeaveMaster (CPF_No, Name, Designation, MNT, YR, LeaveStatus,CurrYear,Sap_No,DesigIndex)" &
"VALUES (@CPF_No, @Name, @Designation, @MNT, @YR, @LeaveStatus, CurrYear, @Sap_No, @DesigIndex) ; "
Try
LvMasterCmd.Parameters.AddWithValue("@Sap_No", IntArr(0))
LvMasterCmd.Parameters.AddWithValue("@DesigIndex", IntArr(1))
LvMasterCmd.Parameters.AddWithValue("@CurrYear", IntArr(2))
LvMasterCmd.Parameters.AddWithValue("@CPF_No", StrArr(0).ToString)
LvMasterCmd.Parameters.AddWithValue("@Name", StrArr(1).ToString)
LvMasterCmd.Parameters.AddWithValue("@Designation", StrArr(2).ToString)
LvMasterCmd.Parameters.AddWithValue("@MNT", CmbMonth.Text)
LvMasterCmd.Parameters.AddWithValue("@YR", CmbYear.Text)
LvMasterCmd.Parameters.AddWithValue("@LeaveStatus", "N")
LvMasterCmd.ExecuteNonQuery()
LvMasterCmd.Parameters.Clear()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End While
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
Dbconnection.Close()
End Sub
推荐答案
LvMasterCmd.Parameters.AddWithValue("@Sap_No", IntArr(0))
然后通过调试器运行代码。当它命中时,使用调试器来查看您传递给DB的确切内容。然后检查数据库表定义并检查该列所期望的数据类型。如果它不匹配,那就是当你遇到问题时,你可以回溯(或者再次运行它并仔细观察)以找出原因。
很抱歉,但我们不能为你做到这一点 - 时间让你学习一门新的(非常非常有用的)技能:调试!
Then run your code through the debugger. When it hits, use the debugger to look at exactly what you are passing to the DB. Then check the DB table definition and check what datatype that column expects. When it doesn't match, that's when you have a problem, and you can back-track (or run it again and look more closely) to find out why.
Sorry, but we can't do that for you - time for you to learn a new (and very, very useful) skill: debugging!
这篇关于条件表达式中的数据类型不匹配。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!