留言本同一页面留言、显示问题,写不进数据库
自己试着做留言本,遇到很多问题,想在同一页面可以写也可以显示,用了gridview,点击“提交”按钮时没办法写到数据库里。请大家帮忙给看看
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Dim sql As String
sql = "insert into liuyanben ([name],[neirong]) values('sql = sql & Trim(TextBox2.Text) & Trim(TextBox1.Text) ')"
End Sub //这个函数我不知道该放到哪里
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head >
<title>留言本</title>
</head>
<body runat="server" >
<form id="form1" runat="server">
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True"
CellPadding="4" DataSourceID="SqlDataSource1" ForeColor="#333333" GridLines="None"
Height="156px" Width="156px">
<FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
<RowStyle BackColor="#E3EAEB" />
<EditRowStyle BackColor="#7C6F57" />
<SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" />
<PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" />
<HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView> //GridView用的是一个叫liuyanben的数据库
<br />
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:liuyanbenConnectionString %>" //我的数据库连接名命名不太规范
SelectCommand="SELECT * FROM [liuyanben]"></asp:SqlDataSource>
<asp:Label ID="Label1" runat="server" Text="姓名"></asp:Label>
<asp:TextBox ID="TextBox2" runat="server" Height="14px" Width="130px"></asp:TextBox><br />
//姓名填写区
<br />
<asp:TextBox ID="TextBox1" runat="server" Height="106px" Width="247px"></asp:TextBox><br />
//留言填写区
<asp:Button ID="Button1" runat="server" Text="提交留言" onclick="Button1_Click"/>
//onclick这个动作不知道定义的对不对
</form>
</body>
</html>
------解决方案--------------------没有InsertCommand和UpdateCommand