這裡蒐索程式師資訊,查找有用的技術資料
当前位置:首页 » 编程语言 » asp参数化sql添加数据
扩展阅读
webinf下怎么引入js 2023-08-31 21:54:13
堡垒机怎么打开web 2023-08-31 21:54:11

asp参数化sql添加数据

发布时间: 2022-05-07 01:56:57

⑴ 如何向asp网页中添加sql数据程序

用SQL语句写入数据库记录
sql="insert into(name,tjr,jifen) values('name的值','tjr的值','jifen的值')" 'sql写入数据库语句
conn.exeucte(sql) '发送sql命令

⑵ asp.net如何在SQL中插入数据

strconn.ConnectionString = "server=localhost;Database=post;uid=;pwd=";

string strSql = "Insert Into post(name,subject,message,[date],ip) values("+strname+","+strSubject+","+strMsg+", "+strDate+", "+strIP+")";

⑶ asp 来连接 sql2008的并添加数据怎么做

asp使用sql2008连接数据库并添加数据的方法:
1、建立数据库连接。
2、使用sql语句插入数据。
举例:

建立数据库连接:
sing System;
sing System.Collections.Generic;
sing System.Linq;
sing System.Web;
sing System.Data.SqlClient;

// <summary>
// DBHelper 的摘要说明
// </summary>
amespace testDAO.Library

public class DBHelper
{//server=.;Trusted_Connection=SSPI;database=easylife
private String connectionString = "server=.;database=easylife;uid=sa;pwd=root";

public SqlDataReader ExecuteReader(String sql)
{
SqlConnection connection = new SqlConnection(connectionString);
connection.Open();

SqlCommand command = new SqlCommand(sql,connection);

SqlDataReader result = command.ExecuteReader();

return result;
}

public bool ExecuteCommand(String sql)
{
bool result = false;

try
{
SqlConnection connection = new SqlConnection(connectionString);
connection.Open();

SqlCommand command = new SqlCommand(sql,connection);
//command.Connection = connection;
//command.CommandText = sql;
command.ExecuteNonQuery();

connection.Close();

result = true;
}
catch (Exception e)
{
throw e;
}

return result;
}

}
执行插入的方法:
public bool AddUser(User user)
{
bool result = false;
String sql = "";

sql = "insert into table_user (userName,userLogin,userPwd)values(";
sql += "'" + user.UserName + "',";
sql += "'" + user.UserLogin + "',";
sql += "'" + user.UserPwd + "'";
sql += ")";

DBHelper helper = new DBHelper();
result = helper.ExecuteCommand(sql);
return result;

}

⑷ asp怎样向sql里面写入数据

你没有给出数据库的名子,呵呵,你自己加吧
代码在下面:
<%@ language=VBscript%>
<%
dim conn
set conn=server.createobject("ADODB.connection")
con.open "PROVIDER=SQLOLEDB;DATA SOURCE=(local);UID=sa;PWD=;DATABASE="你的数据库名称"
set rs=conn.execute("insert into xinxi (id,sex,age) values ('1','2','3') ")
%>

⑸ 在ASP.NET中如何给参数化SQL语句赋参数值

没看懂你说的意思
我一般用着两种方法
string sql = "update ClassType set className='"+className+"' where classId="+classId;

string sql = "insert into TuiGuang(tgName,tgUrl,orderNum)values(@tgName,@tgUrl,@orderNum)";
OleDbParameter[] parms = new OleDbParameter[]{
new OleDbParameter("@tgName",tg.TgName),
new OleDbParameter("@tgUrl",tg.TgUrl),
new OleDbParameter("@orderNum",tg.OrderNum),
};
int num = DBHelper.ExecuteCommand(sql, parms);

⑹ 如何编写asp程序为SQL数据库任意增加空表和表中字段

Dim
SQL
SQL="Create
Table
TableName(UserName
varchar(20))"
Conn.execute(SQL)
这样就创建了一个TableName的表格,里面包括一个字段名Username
字段类型
文本型
长度20