Sql 如何在VBA Excel中显示数据库中的数据?
我在数据库中有一个名为“UOM”的列,我希望通过打开SQL查询将其显示在名为“Qty”的值旁边。但它显示了一个错误,即“该行/列不存在数据”。这是我的密码Sql 如何在VBA Excel中显示数据库中的数据?,sql,vb.net,vba,excel,Sql,Vb.net,Vba,Excel,我在数据库中有一个名为“UOM”的列,我希望通过打开SQL查询将其显示在名为“Qty”的值旁边。但它显示了一个错误,即“该行/列不存在数据”。这是我的密码 Dim Oledbconn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source= C:/inetpub/wwwroot/ProjectIntegrated/Inven.mdb;Persist Security Info=True") Dim
Dim Oledbconn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source= C:/inetpub/wwwroot/ProjectIntegrated/Inven.mdb;Persist Security Info=True")
Dim cmd As New OleDbCommand
Dim reader As OleDbDataReader
cmd.CommandText = "Select UOM FROM Master WHERE IPN = '" & Session("PO IPN")(SummaryCounter) & "'"
cmd.CommandType = CommandType.Text
cmd.Connection = Oledbconn
Oledbconn.Open()
reader = cmd.ExecuteReader()
oSheet.Range("F" & ExcelCounter).Value = "" & Session("PO Qty") + reader.Item("UOM") + (POTableCounter)
oSheet.Range("F" & ExcelCounter).HorizontalAlignment = -4108
Oledbconn.Close()
单独执行读卡器是不行的。你还必须实际阅读。 试试这个:
Oledbconn.Open()
reader = cmd.ExecuteReader()
if (dreader.HasRows)
{
dreader.Read();
oSheet.Range("F" & ExcelCounter).Value = "" & Session("PO Qty") + reader.Item("UOM") + (POTableCounter)
oSheet.Range("F" & ExcelCounter).HorizontalAlignment = -4108
}
Oledbconn.Close()
我已经尝试过了,但是它显示了这个错误“运算符”+“没有为类型“String()”和字符串“EA”定义。EA是@LOCEngineer列中的文本值数据。请发布会话和计量单位的示例值。POTableCounter是整数吗?摆脱
”&
。嗯。。。insertCommands
是否与上述代码有关?会话变量包含哪些值?另外,根据,请始终使用&
运算符连接VB.Net中的字符串。对于大多数字符串,请使用“EA”和“LOT”。它们是@locengineering的文本值在这种情况下,请尝试以下操作:oSheet.Range(“F”和ExcelCounter”).Value=Session(“PO数量”).ToString()&reader.Item(“UOM”).ToString()+(POTableCounter).ToString()