从对象类型system.windows.forms.textbox到已知的托管提供程序本机类型不存在映射 [英] No mapping exists from object type system.windows.forms.textbox to a known managed provider native type
问题描述
SqlStr =INSERT INTO [dbo]。[资产]([AssetID],[AssetBarcode],[AssetName],[AssetType],[AssetDesc],[Store],[AssetLocation],[Manufature],[Brand ],[模型],[AssetMore],[AssetSNo],[AssetTotal],[状态],[条件],[AssetExpiry],[AssetNotes],[PhotoPath],[AssetVendor],[AssetPurRate],[AssetScrap] [AssetYear],[AssetPurDate],[AssetServiceStartDate],[AssetWarranty],[AssetDepreciation],[AssetDepreciationRate])VALUES_
& (@ AssetID,@ AssetBarcode,@ AssetName,@ AssetType,@ AssetDesc,@ Store,@ AssetLocation,@ Manufature,@ Brand,@ Model,@ AssetMore,@ AssetSNo,@ AssetTotal,@ Status,@ Condition,@ AssetExpiry, @ AssetNotes,@ PhotoPath,@ AssetVendor,@ AssetPurRate,@ AssetScrap,@ AssetYear,@ AssetPurDate,@ AssetServiceStartDate,@ AssetWarranty,@ AssetDepreciation,@ AssetDepreciationRate)
'结束如果
尝试
MAINCON.ConnectionString = ConnectionStrinG
MAINCON.Open()
Dim DBF As New SqlClient.SqlCommand(SqlStr,MAINCON)
使用DBF.Parameters
.AddWithValue(@ AssetID,TxtAssetID)
.AddWithValue( @AssetBarcode,TxtAssetBarcode.Text)
.AddWithValue(@ AssetName,TxtAssetName.Text)
.AddWithValue(@ AssetType,TxtAssetType.Text)
.AddWithValue(@ AssetDesc,TxtDescr.Text)
.AddWithValue(@ Store,TxtStoreName.Text)
.AddWithValue(@ AssetLocation,TxtLocation.Text)
.AddWithValue(@ Manufature ,TxtManufacture.Text)
.AddWithValue(@ Brand,TxtBrand.Text)
.AddWithValue(@ Model,TxtModel.Text)
.AddWithValue(@ AssetMore,TxtMoreInfo.Text)
.AddWithValue(@ AssetSNo,TxtSerialNumber.Text)
.AddWithValue(@ AssetTotal ,TxtQty.Text)
.AddWithValue(@ Status,TxtAssetStatus.Text)
.AddWithValue(@ Condition,txtCondition.Text)
.AddWithValue(@ AssetExpiry,TxtExpiry.Value)
.AddWithValue(@ AssetNotes,TxtNote.Text)
.AddWithValue(@ PhotoPath ,PhotoPathForLedgers& \其他人& TxtAssetName.Text& .jpg)
.AddWithValue(@ AssetVendor,TxtVendorName.Text)
.AddWithValue(@ AssetPurRate,TxtPurRate.Text)
.AddWithValue(@ AssetScrap,TxtScrapValue.Text)
.AddWithValue(@ AssetYear,TxtYears.Text)
.AddWithValue(@ AssetPurDate ,TxtpurchaseDate.Value)
.AddWithValue(@ AssetServiceStartDate,TxtServiceStartDate.Value)
.AddWithValue(@ AssetWarranty,TxtWarrantyDate.Value)
.AddWithValue(@ AssetDepreciation,TxtDepreMethod.Text)
.AddWithValue(@ AssetDepreciationRate,TxtDepRate.Text)
结束用
DBF.ExecuteNonQuery()
DBF =无任何
MAINCON.Close()
Catch ex As Exception
MsgBox(ex.Message)
我尝试了什么:
i尝试添加assetid.text但不改变任何一个帮助我提前谢谢
SqlStr = "INSERT INTO [dbo].[Assets] ([AssetID],[AssetBarcode],[AssetName],[AssetType],[AssetDesc],[Store],[AssetLocation],[Manufature],[Brand],[Model],[AssetMore],[AssetSNo],[AssetTotal],[Status],[Condition],[AssetExpiry],[AssetNotes],[PhotoPath],[AssetVendor],[AssetPurRate],[AssetScrap],[AssetYear],[AssetPurDate],[AssetServiceStartDate],[AssetWarranty],[AssetDepreciation],[AssetDepreciationRate]) VALUES " _
& " (@AssetID,@AssetBarcode,@AssetName,@AssetType,@AssetDesc,@Store,@AssetLocation,@Manufature,@Brand,@Model,@AssetMore,@AssetSNo,@AssetTotal,@Status,@Condition,@AssetExpiry,@AssetNotes,@PhotoPath,@AssetVendor,@AssetPurRate,@AssetScrap,@AssetYear,@AssetPurDate,@AssetServiceStartDate,@AssetWarranty,@AssetDepreciation,@AssetDepreciationRate) "
'End If
Try
MAINCON.ConnectionString = ConnectionStrinG
MAINCON.Open()
Dim DBF As New SqlClient.SqlCommand(SqlStr, MAINCON)
With DBF.Parameters
.AddWithValue("@AssetID", TxtAssetID)
.AddWithValue("@AssetBarcode", TxtAssetBarcode.Text)
.AddWithValue("@AssetName", TxtAssetName.Text)
.AddWithValue("@AssetType", TxtAssetType.Text)
.AddWithValue("@AssetDesc", TxtDescr.Text)
.AddWithValue("@Store", TxtStoreName.Text)
.AddWithValue("@AssetLocation", TxtLocation.Text)
.AddWithValue("@Manufature", TxtManufacture.Text)
.AddWithValue("@Brand", TxtBrand.Text)
.AddWithValue("@Model", TxtModel.Text)
.AddWithValue("@AssetMore", TxtMoreInfo.Text)
.AddWithValue("@AssetSNo", TxtSerialNumber.Text)
.AddWithValue("@AssetTotal", TxtQty.Text)
.AddWithValue("@Status", TxtAssetStatus.Text)
.AddWithValue("@Condition", txtCondition.Text)
.AddWithValue("@AssetExpiry", TxtExpiry.Value)
.AddWithValue("@AssetNotes", TxtNote.Text)
.AddWithValue("@PhotoPath", PhotoPathForLedgers & "\Others\" & TxtAssetName.Text & ".jpg")
.AddWithValue("@AssetVendor", TxtVendorName.Text)
.AddWithValue("@AssetPurRate", TxtPurRate.Text)
.AddWithValue("@AssetScrap", TxtScrapValue.Text)
.AddWithValue("@AssetYear", TxtYears.Text)
.AddWithValue("@AssetPurDate", TxtpurchaseDate.Value)
.AddWithValue("@AssetServiceStartDate", TxtServiceStartDate.Value)
.AddWithValue("@AssetWarranty", TxtWarrantyDate.Value)
.AddWithValue("@AssetDepreciation", TxtDepreMethod.Text)
.AddWithValue("@AssetDepreciationRate", TxtDepRate.Text)
End With
DBF.ExecuteNonQuery()
DBF = Nothing
MAINCON.Close()
Catch ex As Exception
MsgBox(ex.Message)
What I have tried:
i have tried adding assetid.text but not change any one help me thanks in advance
推荐答案
如果数据库中的字段是整数类型,则必须将文本框的字符串解析为有效整数:
If the field in your database is of an integer type, you have to parse the string of the textbox to a valid integer:
.AddWithValue("@AssetID", Int.Parse(TxtAssetID.Text))
检查文本框中的文本是否为有效整数也是一个好主意; TryParse
方法是一个很好的工具:
It can also be a good idea to check whether the text in the textbox is a valid integer ; TryParse
method is a good tool for that:
Dim id As Integer
If Int.TryParse(TxtAssetID.Text, id) Then
DBF.Parameters.AddWithValue("@AssetID", id)
Else
'' The text in the textbox was not a valid integer representation.
'' You may have to handle that case here.
End If
这篇关于从对象类型system.windows.forms.textbox到已知的托管提供程序本机类型不存在映射的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!