<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Import Namespace="System.Web.Configuration" %><script runat="server"> protected void Button1_Click(object sender, EventArgs e)
{ SqlDataSource1.InsertParameters["tilte"].DefaultValue = TextBox1.Text;
SqlDataSource1.InsertParameters["content"].DefaultValue = TextBox2.Text;
SqlDataSource1.InsertParameters["atime"].DefaultValue = DateTime.Now.ToString();
SqlDataSource1.Insert();
}
</script><asp:Content ID="Content3" ContentPlaceHolderID="ContentPlaceHolder3" Runat="Server">
<div class="content"> <table cellspacing="1"
style="width: 100%; border-style: solid; border-width: 1px">
<tr>
<td>
<asp:Label ID="Label1" runat="server" Text="标题:"></asp:Label>
</td>
<td>
<asp:TextBox ID="TextBox1" runat="server" Height="16px" Width="491px"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label2" runat="server" Text="内容:"></asp:Label>
</td>
<td>
<asp:TextBox ID="TextBox2" runat="server" Height="321px" TextMode="MultiLine"
Width="606px"></asp:TextBox>
</td>
</tr>
<tr>
<td colspan="2">
<table class="style1">
<tr>
<td>
<asp:Button ID="Button1" runat="server" Text="提交" onclick="Button1_Click" />
</td>
<td>
<asp:Button ID="Button2" runat="server" Text="返回" />
</td>
</tr>
</table>
</td>
</tr>
</table>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:conn1 %>"
SelectCommand="SELECT * FROM [article]"
InsertCommand="INSERT INTO [article] (title,content,atime) values (@title,@content,@atime)">
<InsertParameters>
<asp:Parameter Name="title" />
<asp:Parameter Name="content" />
<asp:Parameter Name="atime" />
</InsertParameters> </asp:SqlDataSource>
</div>
</asp:Content>
求解,谢谢各位!在线等
解决方案 »
- frame点击左侧菜单,右侧网页无法显示问题
- 关于.net 加密MD5的问题
- Visual studio2008 的websetup project中如何修改目标路径?
- asp.net ajax框架取消异步发送,有些问题。
- <%# ... %>和 <%= ...%> 的区别在哪里?
- 问个菜的问题login控件
- 2003下IIS的问题,200分的帖子
- 请教各位.在WEB应用程序中有必要用到多线程吗?在什么情况下需要用到多线程?如果用到的数据库太大(200万记录以上),有什么方法提高性能?是
- *** 《关于ASP.NET开发webOA的大讨论》 *** (总共贡献300分)
- 请问在asp.net中如何进行差错控制?请大虾们指教
- 正则表达式
- asp.net 压缩文件组件
SqlDataSource1.InsertParameters["tilte"].DefaultValue = TextBox1.Text;
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:conn1 %>"
SelectCommand="SELECT * FROM [article]"
InsertCommand="INSERT INTO [article] (title,content,atime) values (@title,@content,@atime)">
<InsertParameters>
<asp:Parameter Name="title" formfield="TextBox1" />
<asp:Parameter Name="content" formfield="TextBox2" />
<asp:Parameter Name="atime" />
</InsertParameters> </asp:SqlDataSource>
<script runat="server"> protected void Button1_Click(object sender, EventArgs e)
{
SqlDataSource1.InsertParameters["atime"].DefaultValue = DateTime.Now.ToString();
SqlDataSource1.Insert();
}
</script>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><script runat="server">
private void InsertShipper (object source, EventArgs e) {
SqlDataSource1.Insert();
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>ASP.NET Example</title>
</head>
<body>
<form id="form1" runat="server"> <asp:dropdownlist
id="DropDownList1"
runat="server"
datasourceid="SqlDataSource1"
datatextfield="CompanyName"
datavaluefield="ShipperID" /><!-- Security Note: The SqlDataSource uses a FormParameter,
Security Note: which does not perform validation of input from the client.
Security Note: To validate the value of the FormParameter, handle the Inserting event. --> <asp:sqldatasource
id="SqlDataSource1"
runat="server"
connectionstring="<%$ ConnectionStrings:MyNorthwind %>"
selectcommand="SELECT CompanyName,ShipperID FROM Shippers"
insertcommand="INSERT INTO Shippers (CompanyName,Phone) VALUES (@CoName,@Phone)">
<insertparameters>
<asp:formparameter name="CoName" formfield="CompanyNameBox" />
<asp:formparameter name="Phone" formfield="PhoneBox" />
</insertparameters>
</asp:sqldatasource> <br /><asp:textbox
id="CompanyNameBox"
runat="server" /> <asp:RequiredFieldValidator
id="RequiredFieldValidator1"
runat="server"
ControlToValidate="CompanyNameBox"
Display="Static"
ErrorMessage="Please enter a company name." /> <br /><asp:textbox
id="PhoneBox"
runat="server" /> <asp:RequiredFieldValidator
id="RequiredFieldValidator2"
runat="server"
ControlToValidate="PhoneBox"
Display="Static"
ErrorMessage="Please enter a phone number." /> <br /><asp:button
id="Button1"
runat="server"
text="Insert New Shipper"
onclick="InsertShipper" /> </form>
</body>
</html>
ConnectionString="<%$ ConnectionStrings:DBaseConnectionString %>"
InsertCommand="INSERT INTO Tb(a, b) VALUES (@a, @b)"
SelectCommand="SELECT tb.* FROM tb">
<InsertParameters>
<asp:Parameter Name="a" />
<asp:Parameter Name="b" />
</InsertParameters>
</asp:SqlDataSource>
对a,b赋值并保存的代码:
SqlDataSource1.InsertParameters["a"].DefaultValue = "值1"; SqlDataSource1.InsertParameters["b"].DefaultValue = "值2";
SqlDataSource1.Insert();
看看scott教程SqlDataSource 操作
SqlDataSource1.InsertParameters["tilte"].DefaultValue = TextBox1.Text;<asp:Parameter Name="title" />