1--------------------------------------------------------视图修改 删除 和添加操作
create table Users
(
id int not null,
UserName varchar(20) not null,
UserPassword varchar(20) not null
)
Use book
Create view au_book
(id,UserName,UserPassword)
AS
Select *
From Users
insert au_book(UserName,UserPassword)
values('2','2')
update au_book
set UserName='3dd'
where id=2
delete from au_book
where id=1
2-----------------------------------------------------同个解决方案,不同项目间的Cookies如何获取--------1
在A项目中
string dayfrom ="sssssssssssssssssss";
HttpCookie c = new HttpCookie("dayfrom");
c.Value = dayfrom;
c.Expires = DateTime.Now.AddDays(1);//这里设Cookie 存的时间为1天
Response.Cookies.Add(c);
在B项目中
Response.Write(Request.Cookies["dayfrom"].Value.ToString());
3---------------------------------------------------string ip1=192.168.4.1;
string ip2=192.168.4.10;
我想实现,IP地址从1到10这一网段逐个处理,-拆分------------------------
protected void Button1_Click(object sender, EventArgs e)
{
string ip1="192.168.4.11";
string ip2="192.168.4.123";
string b1="";
string b2 = "";
string s = "";
if (ip1[ip1.Length - 2] =='.') b1 =ip1[ip1.Length-1].ToString();
if (ip1[ip1.Length - 3] == '.') b1 =ip1[ip1.Length - 2].ToString()+ ip1[ip1.Length - 1].ToString();
if (ip1[ip1.Length - 4] == '.') b1 =ip1[ip1.Length - 3].ToString()+ ip1[ip1.Length - 2].ToString() + ip1[ip1.Length - 1].ToString();
if (ip2[ip2.Length - 2] == '.') b2 = ip2[ip2.Length - 1].ToString();
if (ip2[ip2.Length - 3] == '.') b2 = ip2[ip2.Length - 2].ToString() + ip2[ip2.Length - 1].ToString();
if (ip2[ip2.Length - 4] == '.') b2 = ip2[ip2.Length - 3].ToString() + ip2[ip2.Length - 2].ToString() + ip2[ip2.Length - 1].ToString();
int i = Convert.ToInt16(b1);
int j = Convert.ToInt16(b2);
while(i <=j )
{
s+=i+",";
i++;
}
Response.Write(s);
}
4----------------------------------------------为什么girdview等控件中生成insert update 和delete语句没法
表里没有设主键、
5---------------------------------------------有一个表,用select 。。。 from table where name=‘。。’
查到n行结果,要求列出结果,每行之前还加一个编辑和删除的按钮 --------------
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="edit.aspx.cs" Inherits="_6_edit" %>
<!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 runat="server">
<title>无标题页 </title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server"> </asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button" />
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1">
<Columns>
<asp:BoundField DataField="id" HeaderText="id" InsertVisible="False" ReadOnly="True"
SortExpression="id" />
<asp:BoundField DataField="UserName" HeaderText="UserName" SortExpression="UserName" />
<asp:BoundField DataField="UserPassword" HeaderText="UserPassword" SortExpression="UserPassword" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString=" <%$ ConnectionStrings:bookConnectionString %>"
DeleteCommand="delete from Users where id=@id" SelectCommand="SELECT * FROM [Users] where id=@id"
UpdateCommand="update Users set UserName=@UserName, UserPassword=@UserPassword where id=@id">
<SelectParameters>
<asp:ControlParameter ControlID="TextBox1" Name="id" PropertyName="Text" />
</SelectParameters>
<DeleteParameters>
<asp:Parameter Name="id" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="UserName" />
<asp:Parameter Name="UserPassword" />
<asp:Parameter Name="id" />
</UpdateParameters>
</asp:SqlDataSource>
</div>
</form>
</body>
</html>
6------------------------------------------------------再请教linkbotton删除问题
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="_7_Default2" %>
<!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 runat="server">
<title>无标题页 </title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="id"
DataSourceID="SqlDataSource1" EnableViewState="False">
<Columns>
<asp:BoundField DataField="id" HeaderText="id" InsertVisible="False" ReadOnly="True"
SortExpression="id" />
<asp:BoundField DataField="name" HeaderText="name" SortExpression="name" />
<asp:BoundField DataField="title" HeaderText="title" SortExpression="title" />
<asp:BoundField DataField="content" HeaderText="content" SortExpression="content" />
<asp:BoundField DataField="date" HeaderText="date" SortExpression="date" />
<asp:TemplateField HeaderText="delete">
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CommandArgument=' <%# Eval("id") %>' OnClick="LinkButton1_Click">LinkButton </asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString=" <%$ ConnectionStrings:bookConnectionString %>"
SelectCommand="SELECT * FROM [book]"> </asp:SqlDataSource>
</div>
</form>
</body>
</html>
---------------------------------CS 代码
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class _7_Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void LinkButton1_Click(object sender, EventArgs e)
{
string id = ((System.Web.UI.WebControls.LinkButton)(sender)).CommandArgument;
SqlConnection conn = new SqlConnection("Data Source=.;Initial Catalog=book;Integrated Security=True");
conn.Open();
SqlCommand myCommand = new SqlCommand("delete from book where id='" + id + "'", conn);
myCommand.ExecuteNonQuery();
conn.Close();
}
}
7-------------------------------------------------对课程表(课程号,课程名,教师名)
教师表(教师号,教师名)
课程时间表(课程号,上课时间)
要对这样的表进行插入和更新所有字段的存储过程怎么写呢-----------------------
create proc P_update
(@课程号 int
@教师号 int
)
as
begin
update 课程表
set 课程名=@课程名,教师名=@教师名
where 课程号=@课程号
update 教师表
set 教师名=@教师名
where 教师号=@教师号
update 课程时间表
set 上课时间=@上课时间
where 课程号=@课程号
end
8-------------------------------------我数据库中3条记录
怎么把读取出来的值放到数组中,并把值从数组中读取出来 ----------------------------------
Hashtable ht = new Hashtable();
ht.Add("Title", TextBoxTitle.Text);
ht.Add("Content", TextBoxContent.Text);