VB.NET为什么写汉字进数据库的时候出现乱码

2024-12-17 14:08:46
推荐回答(2个)
回答1:

Public Function addEquipment() As Integer
Dim flag As Integer = 0
Dim strsql As String = ""
emditInfor = New DBHelper()'DBHelper()为数据库操作文件,包括数据库的连接插入更新查找等等
Try
strsql = "INSERT INTO Equipment ("
strsql &= "AssetsID,"
...
strsql &= "Size)"
strsql &= "VALUES ("
strsql &= "@AssetsID,"
...
strsql &= "@Size)"
Dim cmd As SqlCommand = emditInfor.GetSqlStringCommond(strsql)
emditInfor.AddInParameter(cmd,"@AssetsID",SqlDbType.NVarChar, "1314")
...
emditInfor.AddInParameter(cmd, "@Size", SqlDbType.NVarChar, "5")
flag = emditInfor.ExecuteNonQuery(cmd)'返回受影响的行数
Catch ex As Exception
End Try
Return flag
End Function
像这样以参数的形式传值进去就可以了。

回答2:

是不是应该在你输入的汉字打上双引号,把汉字括起来。。还是在=之前cstr()