社区
C#
帖子详情
在commandText中传入参数
compasshr
2003-08-20 03:35:02
如何在:
string strA,strB;
CommandText="insert into [tableName] values( , )"
// 我要把strA,strB传入到这个sql语句中,如何做
...全文
70
2
打赏
收藏
在commandText中传入参数
如何在: string strA,strB; CommandText="insert into [tableName] values( , )" // 我要把strA,strB传入到这个sql语句中,如何做
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
2 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
compasshr
2003-08-20
打赏
举报
回复
可不可以说一下具体是什么意思
abcynic
2003-08-20
打赏
举报
回复
CommandText="insert into [tableName] values(\'"+strA+"\' ,\'"+strB+"\' )"
SQLite ADO.NET 2.03.5 +示例源码
using System; using System.Collections.Generic; using System.
Text
; using System.Web; using System.Configuration; using System.Data; using System.Data.SQLite; namespace DAL { public class Sqlite { ///
/// 获得连接对象 ///
///
public static SQLiteConnection GetSQLiteConnection() { return new SQLiteConnection("Data Source=" + System.Web.HttpCon
text
.Current.Server.MapPath(System.Configuration.ConfigurationManager.AppSettings["db"].ToString())); } private static void Prepare
Command
(SQLite
Command
cmd, SQLiteConnection conn, string cmd
Text
, params object[] p) { if (conn.State != ConnectionState.Open) conn.Open(); cmd.Parameters.Clear(); cmd.Connection = conn; cmd.
Command
Text
= cmd
Text
; cmd.
Command
Type =
Command
Type.
Text
; cmd.
Command
Timeout = 30; if (p != null) { foreach (object parm in p) cmd.Parameters.AddWithValue(string.Empty, parm); //for (int i = 0; i < p.Length; i++) // cmd.Parameters[i].Value = p[i]; } } public static DataSet ExecuteDataset(string cmd
Text
, params object[] p) { DataSet ds = new DataSet(); SQLite
Command
command
= new SQLite
Command
(); using (SQLiteConnection connection = GetSQLiteConnection()) { Prepare
Command
(
command
, connection, cmd
Text
, p); SQLiteDataAdapter da = new SQLiteDataAdapter(
command
); da.Fill(ds); } return ds; } public static DataRow ExecuteDataRow(string cmd
Text
, params object[] p) { DataSet ds = ExecuteDataset(cmd
Text
, p); if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0) return ds.Tables[0].Rows[0]; return null; } ///
/// 返回受影响的行数 ///
///
a ///
传入
的
参数
///
public static int ExecuteNonQuery(string cmd
Text
, params object[] p) { SQLite
Command
command
= new SQLite
Command
(); using (SQLiteConnection connection = GetSQLiteConnection()) { Prepare
Command
(
command
, connection, cmd
Text
, p); return
command
.ExecuteNonQuery(); } } ///
/// 返回SqlDataReader对象 ///
///
///
传入
的
参数
///
public static SQLiteDataReader ExecuteReader(string cmd
Text
, params object[] p) { SQLite
Command
command
= new SQLite
Command
(); SQLiteConnection connection = GetSQLiteConnection(); try { Prepare
Command
(
command
, connection, cmd
Text
, p); SQLiteDataReader reader =
command
.ExecuteReader(
Command
Behavior.CloseConnection); return reader; } catch { connection.Close(); throw; } } ///
/// 返回结果集
中
的第一行第一列,忽略其他行或列 ///
///
///
传入
的
参数
///
public static object ExecuteScalar(string cmd
Text
, params object[] p) { SQLite
Command
cmd = new SQLite
Command
(); using (SQLiteConnection connection = GetSQLiteConnection()) { Prepare
Command
(cmd, connection, cmd
Text
, p); return cmd.ExecuteScalar(); } } ///
/// 分页 ///
///
///
///
///
///
///
///
public static DataSet ExecutePager(ref int recordCount, int pageIndex, int pageSize, string cmd
Text
, string count
Text
, params object[] p) { if (recordCount < 0) recordCount = int.Parse(ExecuteScalar(count
Text
, p).ToString()); DataSet ds = new DataSet(); SQLite
Command
command
= new SQLite
Command
(); using (SQLiteConnection connection = GetSQLiteConnection()) { Prepare
Command
(
command
, connection, cmd
Text
, p); SQLiteDataAdapter da = new SQLiteDataAdapter(
command
); da.Fill(ds, (pageIndex - 1) * pageSize, pageSize, "result"); } return ds; } } }
在SQL语句
中
使用
参数
在SQL语句
中
使用":
参数
名"的方法
传入
参数
,效果图: **************************************************************************************************** 新建空白工程,在窗体
中
放入一ADODataSet,三对ADODataSet,DataSource,DBGrid。 源代码如下:...
在c#
中
执行sql语句时传递
参数
c#
中
与数据库打交道,免不了要用到各种sql语句,而给sql语句传
参数
也是不可避免的。以下是我在此方面上的一点总结(高手勿见笑): 1> 直接写入法: 例如: int id =1; string name="lui"; cmd.
command
text
="insert into tuserlogin
存储过程/SQL
中
参数
传入
传出的写法
string connstr = "Data Source = localhost; Initial Catalog = NorthWind; User ID = sa; Password = sapass"; SqlConnection conn = new SqlConnection(ConnString); Sql
Command
执行多条SQL语句,执行数据库事务(可
传入
Sql
参数
)
摘录地址:http://blog.csdn.net/hanxuemin12345/article/details/9989165 注:仅供学习使用。 上篇博客,实例介绍了一个事务执行多条SQL语句函数(int ExecuteSqlTran(List<String> SQLStringList))点击打开链接,方便之余又发现了它的缺陷——不能
传入
Sql语句的
参数
,只能靠拼接字符串...
C#
110,534
社区成员
642,575
社区内容
发帖
与我相关
我的任务
C#
.NET技术 C#
复制链接
扫一扫
分享
社区描述
.NET技术 C#
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
让您成为最强悍的C#开发者
试试用AI创作助手写篇文章吧
+ 用AI写文章