⑴ 如何向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