这是我的代码如何解决此问题解决索引的这个问题 [英] Here is my Code How to Slove this problem resolve this problem of indexing
本文介绍了这是我的代码如何解决此问题解决索引的这个问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是代码
this is the code of
"
Private Sub GetQuantity()
Try
sqL = "SELECT StocksOnhand FROM Item WHERE ItemNo = " & txtItemNo.Text & ""
ConnDB()
cmd = New OleDbCommand(sqL, conn)
dr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
If dr.Read = True Then
getStocksOnHand = dr(0)
End If
Catch ex As Exception
MsgBox(ex.Message)
Finally
cmd.Dispose()
conn.Close()
End Try
End Sub
i希望在c#中获取此代码但在行getStocksOnHand = dr(0);
存在无法隐式将字符串转换为int。
如何解决它
"
i want to get this code into in c# but in the line getStocksOnHand=dr(0);
there is the problem that " can not implicitly convert string to int.
how to solve it
推荐答案
C#中的索引器是括号,而不是括号。此外,您似乎试图将字符串变量影响为整数变量。
因此,所述行应该是
Indexer in C# is the bracket, not the parenthesis. Moreover, you seem to try to affect a string variable to an integer variable.
Thus, said line should be
getStocksOnHand = int.Parse(dr[0].ToString());
或者更健壮的方式来处理错误的值:
Or a more robust way that would take care about wrong values:
int value;
if (int.TryParse(dr[0].ToString(), out value)) {
getStocksOnHand = value;
// ...
}
希望这会有所帮助。
Hope this helps.
这篇关于这是我的代码如何解决此问题解决索引的这个问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文