我对此很陌生。 我有一个 MS Access 数据库(.mdb 只有两列),我已使用 gridview 链接它。它在网页上显示数据库中的所有内容。我还有一个用于文本框的发布按钮(就像 Facebook 中发布状态的按钮)。 GridView 仅显示输入的文本并自动计时。 问题是,我似乎无法编写单击时更新数据库的代码。 我在 web.config 文件中添加了一个连接。 命名空间已声明,
在 .aspx 文件中,我使用了 sql 数据源
<asp:SqlDataSource ID="Test" runat="server"
ConnectionString="<%$ ConnectionStrings:DB1 %>"
ProviderName="<%$ ConnectionStrings:DB1.ProviderName %>"
SelectCommand="SELECT [Message], [Date] FROM [DB1] order by id desc">
</asp:SqlDataSource>
背后的代码如下所示 -
protected void btnpost_Click(object sender, EventArgs e)
{
this.******** = "INSERT INTO DB1 (message) + values ('" + txtpost.text + "')";
gridview.databind();
txtpost.Text="";
}
有人能告诉我完成这项工作的“********”中包含什么吗?
最佳答案
缺少的部分是:
Test.SelectCommand = "INSERT INTO DB1 (message) + values ('" + txtpost.Text + "')";
关于c# - 无法找到使用 C# 插入 AS Access 数据库的代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30724648/