asp sql(asp中sql查询语句)

本文目录
asp中sql查询语句
Select *from admin的意思是从数据库中的admin表中查,查询的条件就是admin表中的name列和password列是否有数据与“&name&“和“&password&“相同,“&name&“和“&password&“所代表的意思应该是应用层输入的用户名和密码。 这个语句应该是sql中最基本的了吧 除了select * from table。
ASP怎么连接SQL数据库
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient; //注意需要添加此句
namespace aspnet3
{
public partial class datatest : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string strconn = “server=localhost;uid=sa;pwd=longlt;database=School“;
SqlConnection conn = new SqlConnection(strconn); //创建连接
string sql = “select * from students“;
conn.Open();
SqlCommand cmd = new SqlCommand(sql, conn); //执行查询
Response.Write(“连接成功“);
SqlDataReader dr = cmd.ExecuteReader(); //查询结果
if (dr.Read())
{
//利用dr[索引]对数据库表进行操作,dr返回object;
//可以用字段做索引,也可用列号0,1..做索引
Response.Write(dr.ToString() + “《br》“);
}
// this.Lab.Text = “suc“;
}
}
}
在上面的例子中,我们连接了一个sa下的School数据库,并查询了其中students字段的内容。
连接数据库分为三个步骤:先定义连接信息,再创建一个连接,最后打开连接
string strconn = “server=localhost;uid=sa;pwd=longlt;database=School“; //在这一段修改数据库的信息SqlConnection conn = new SqlConnection(strconn);//创建连接conn.Open();//打开连接怎样将asp与sql连接
首先确定你要连接的sql
server服务器有没有开启,sql
server服务有没有启动,然后确定此计算机上是否有名为news的数据库,之后确定sa的用户名密码是否正确。
asp中SQL语句的写法
1. mydate=myyear & “-“ & mymonth & “-“ & 1
改正:最后的1是字符串,和前面的年月相连,比如2008-12-1,1要使用双引号““括起来。
2. lookfor是文本型吗?如果是文本型,写成request(“lookfor“)=“yes“是正确的,如果是布尔型,那么要写成request(“lookfor“)=true
3. :你的SqlStr函数是这样写的吗?
Function SqlStr( data )
SqlStr = ““ & Replace( data “, ““ ) & ““
End Function
4. sql内错误,b69前缺少一个and;
改正:
if request(“lookfor“)=“yes“ then
sql=“select * from diaocha where b75 = “ & sqlstr(oabusyname) & “ and b69 between “ & mydate & “ and “ & mydate1 & “ order by id desc“
5.sql重复:已经有了sql,为什么还继续写if ... the sql=....
如果要判断,就这样写
if request(“lookfor“)=“yes“ then
sql=“select * from diaocha where b75 = “ & sqlstr(oabusyname) & “ b69 between “ & mydate & “ and “ & mydate1 & “ order by id desc“
else
sql=“select * from diaocha where b75 =“ & sqlstr(oabusyname) & “ order by id desc“
end if
6.如果是access数据库,日期mydate最好要使用#括起来,asp可以更好的读取。
mydate = “#“ & myyear & “-“ & mymonth & “-“ & “1#“
ASP 怎么连接SQL数据库
ASP与SQL数据库连接语句具体如下:
Set conn = Server.CreateObject(“ADODB.Connection“)
connstr = “provider=Sqloledb;server=服务器名;uid=用户名;pwd=密码;database=数据库名“
conn.Open connstr
If Err Then
err.Clear
Set conn = Nothing
Response.Write “数据库连接出错,请检查连接字串“
Response.End
扩展资料:
SQL常用命令使用方法:
(1) 数据记录筛选:
sql=“select * from 数据表 where 字段名=字段值 order by 字段名 “
sql=“select * from 数据表 where 字段名 like ‘%字段值%‘ order by 字段名 “
sql=“select top 10 * from 数据表 where 字段名 order by 字段名 “
sql=“select * from 数据表 where 字段名 in (‘值1‘,‘值2‘,‘值3‘)“
sql=“select * from 数据表 where 字段名 between 值1 and 值2“
(2) 更新数据记录:
sql=“update 数据表 set 字段名=字段值 where 条件表达式“
sql=“update 数据表 set 字段1=值1,字段2=值2 …… 字段n=值n where 条件表达式“
(3) 删除数据记录:
sql=“delete from 数据表 where 条件表达式“
sql=“delete from 数据表“ (将数据表所有记录删除)
asp中的sql语句
sql=“select * from secret where id=’request.form(“soso“)’“这要看你数据库中id的类型是什么
如果id是整型那就
string sql = “select * from secret where id=“+int.Parse(request.form(“soso“));//从文本框提取是字符串类型的,所以要转换成整型
如果id是字符串类型那就
string sql = “select * from secret where ID=’“+request.form(“soso“)+“’“;//从文本框提取是字符串类型的,所以不需要转换
asp和sql是什么关系
ASP,Active Server Pages,活动服务页,是微软的一种动态网站服务器端脚本技术。
SQL,Structured Query Language,结构化查询语言,用来查询、更新和管理关系数据库的语言。
SQL Server,支持SQL语言的数据库服务器,通常指微软的SQL Server。
它们的关系是这样:ASP是应用平台,ASP可以通过调用OLE DB以SQL语法操作SQL Server。
另注:
OLE DB,没有OLDB,是微软提出的一种技术标准,目的是提供一种统一的数据访问接口。它是一种数据访问模型,基于COM的数据存储对象,能提供对所有类型的数据的操作,甚至能在离线的情况下存取数据。
OLE DB位于ODBC层与应用程序之间。
asp的sql添加语句
语法错了!sql=“insert
into
news(title,note)
values(’“+title+“’,’“+note+“’)“
values里面应该是填对应的控件的
如果你是用textBox
就要写textBox.text
sql=“insert
into
news(title,note)
values(’“+textBox1.text+“’,’“+textBox2.text+“’)“
你要在textBox1属性那里设置一下!我这里对应是textBox1
title
不懂联系我!

本文相关文章:
关于dropdownlist说法错误的是()(asp.net.明天考试急求答案请带解释,谢谢)
2026年10月9日 14:30
mssqlserver(mssqlserver和sqlexpress的区别)
2026年9月14日 02:20
repeater分页(asp.net(c#)中Repeater分页的问题)
2026年8月15日 20:20
更多文章:
another time(another time和other time的区别)
2026年10月11日 05:00







