【发布时间】:2021-07-07 03:58:38
【问题描述】:
我正在使用 VB.Net (VS2019) 和 Telegram.bot API。在 C# 示例中,它们展示了如何将项目添加到回复键盘。恐怕我根本不理解 IEnumerable 的概念,但无论如何我已经设法将 C# 转换为可工作的 VB.Net 代码。
这是代码: C#
if (update.Message.Text.Contains("/reply"))
{
var keyboard = new ReplyKeyboardMarkup
{
Keyboard = new KeyboardButton[][]{
new KeyboardButton[]{
new KeyboardButton("Button 1"), //column 1 row 1
new KeyboardButton("Button 2") //column 1 row 2
},// column 1
new KeyboardButton[]{
new KeyboardButton("Button 3") //col 2 row 1
} // column 2
},
ResizeKeyboard = true
}; ;
bot.SendMessage(update.Message.Chat.Id, "new keyboard", replyMarkup: keyboard);
}
VB代码是
If update.Message.Text.Contains("/reply") Then
Dim keyboard = New ReplyKeyboardMarkup With {
.Keyboard = New KeyboardButton()() {New KeyboardButton() {New KeyboardButton("Button 1"), New KeyboardButton("Button 2")}, New KeyboardButton() {New KeyboardButton("Button 3")}},
.ResizeKeyboard = True
}
bot.SendMessage(update.Message.Chat.Id, "new keyboard", replyMarkup:=keyboard)
End If
我的问题是如何即时更新它? 我从 sqlite 读取表格,我想创建按钮来保存记录的 rowids.. 所以我有
mySQL = "select * from products;"
Dim cs As String = "URI=file:" & DBName
Using con As New SQLiteConnection(cs)
con.Open()
Dim dr As SQLiteDataReader
Using DBcmd As New SQLiteCommand(con)
DBcmd.CommandText = mySQL
dr = DBcmd.ExecuteReader()
While dr.Read()
MsgText &= String.Format("Code: *{0}* [{1}]({3}), Price: ${2}", dr("Code"), Replace(dr("ProdName"), "-", " "), dr("Price"), dr("ProdURL")) & vbCrLf
End While
End Using
con.Close()
End Using
在该循环中,我想构建键盘,为每次出现的dr("code") 添加一个按钮作为按钮的文本。
请帮忙?
【问题讨论】:
-
IEnumerable(Of T)只不过是可以在每个元素上迭代的T序列。任何可以在序列中提供元素的东西都满足接口。 (Linq 提供了一个函数式编程接口,用于操作IEnumerable的实现所提供的序列)。
标签: c# vb.net telegram-bot ienumerable