社区
C#
帖子详情
关于SqlDataAdapter,SqlConnection,SqlCommand的用法,最好举例说明一个,再线等,急!!!!!!!!!!!!!!!!!
rain1983
2004-03-14 10:32:21
关于SqlDataAdapter,SqlConnection,SqlCommand的用法,最好举例说明一个,再线等,急!!!!!!!!!!!!!!!!!
...全文
580
12
打赏
收藏
关于SqlDataAdapter,SqlConnection,SqlCommand的用法,最好举例说明一个,再线等,急!!!!!!!!!!!!!!!!!
关于SqlDataAdapter,SqlConnection,SqlCommand的用法,最好举例说明一个,再线等,急!!!!!!!!!!!!!!!!!
复制链接
扫一扫
分享
转发到动态
举报
AI
作业
写回复
配置赞助广告
用AI写文章
12 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
calmhawkaaa
2004-03-14
打赏
举报
回复
可以直接将数据表 “拉”到工程里
系统自动生成 SqlConnnection1 SqlDataAdaper1
然后右键 SqlDataAdapter1 生成 dataSet1
在dataSet1 中配置 SqlCommand (insert delete update)
如果SqlServer 有密码 在“窗体设计器生成的代码”中将this.sqlConnection1.ConnectionString = "workstation id=CALMHAWK;packet size=4096;user id=sa;password=****;data source=ca" +
"lmhawk;persist security info=False;initial catalog=student";
加 password=****
popohei
2004-03-14
打赏
举报
回复
可以全部用控件完成
但SqlConnection可能会出错 要自己写Connecttion string
CommanSource
2004-03-14
打赏
举报
回复
QUICK START!
<script language="C#" runat="server">
void Page_Load(Object Src, EventArgs E ) {
String selectCmd;
String state = Request["state"];
if( state == null || !InputValidator.IsValidAnsiTwoCharacterState(state)) {
selectCmd = "select * from Authors";
}
else {
selectCmd = "select * from Authors where state = '" + state + "'";
}
SqlConnection myConnection = new SqlConnection("server=(local)\\NetSDK;database=pubs;Integrated Security=SSPI");
SqlDataAdapter myCommand = new SqlDataAdapter(selectCmd, myConnection);
DataSet ds = new DataSet();
myCommand.Fill(ds, "Authors");
MyDataGrid.DataSource=new DataView(ds.Tables[0]);
MyDataGrid.DataBind();
// capture the time of the current request
// subsequent requests that are cached will show the
// original time
TimeMsg.Text = DateTime.Now.ToString("G");
}
</script>
Firestone2003
2004-03-14
打赏
举报
回复
CSDN上有例子阿!
极限999
2004-03-14
打赏
举报
回复
http://www.csdn.net/develop/read_article.asp?id=23258
hertcloud
2004-03-14
打赏
举报
回复
油箱 给你 个列子!
zhpsam109
2004-03-14
打赏
举报
回复
向各位学习!
draclosta
2004-03-14
打赏
举报
回复
好好看看Data Access Application Block 概述吧
http://www.microsoft.com/china/msdn/library/dnbda/html/daab-rm.asp
caojingui
2004-03-14
打赏
举报
回复
用zhzuo(秋枫)老弟的例子吧
huangsuipeng
2004-03-14
打赏
举报
回复
UP
marvelstack
2004-03-14
打赏
举报
回复
using System;
using System.Data;
using System.Data.OleDb;
namespace ZZ.DAL
{
/// <summary>
/// AccessDbHelper 的摘要说明。
/// </summary>
public class AccessDbHelper
{
private static string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=GMS.mdb;Persist Security Info=False;";
/// <summary>
/// 获取单个值
/// </summary>
/// <param name="strSql"></param>
/// <returns></returns>
public static object ExecuteScalar(string strSql)
{
object o = null;
OleDbConnection myConn = new OleDbConnection(strConn);
OleDbCommand myComm = new OleDbCommand(strSql,myConn);
try
{
myConn.Open();
o = myComm.ExecuteScalar();
}
catch(Exception e)
{
e.ToString();
}
finally
{
myConn.Close();
}
return o;
}
/// <summary>
/// 更新数据
/// </summary>
/// <param name="strSql"></param>
public static int ExecuteNonQuery(string strSql)
{
int count = -1;
OleDbConnection myConn = new OleDbConnection(strConn);
OleDbCommand myComm = new OleDbCommand(strSql,myConn);
try
{
myConn.Open();
count = myComm.ExecuteNonQuery();
}
catch(Exception e)
{
e.ToString();
}
finally
{
myConn.Close();
}
return count;
}
/// <summary>
/// 获取数据读取器
/// </summary>
/// <param name="strSql"></param>
public static OleDbDataReader ExecuteReader(string strSql)
{
OleDbConnection myConn = new OleDbConnection(strConn);
OleDbCommand myComm = new OleDbCommand(strSql,myConn);
myConn.Open();
return myComm.ExecuteReader(CommandBehavior.CloseConnection);
}
/// <summary>
/// 获取数据集
/// </summary>
/// <param name="strSql"></param>
/// <returns></returns>
public static DataSet ExecuteDataSet(string strSql)
{
DataSet ds = new DataSet();
OleDbConnection myConn = new OleDbConnection(strConn);
try
{
OleDbCommand myComm = new OleDbCommand(strSql,myConn);
OleDbDataAdapter myAda = new OleDbDataAdapter(myComm);
myAda.Fill(ds,"TableName");
}
catch(Exception e)
{
e.ToString();
ds = null;
}
finally
{
myConn.Dispose();
}
return ds;
}
}
}
zljblue
2004-03-14
打赏
举报
回复
SqlConnection mycon=new SqlConnection("server=服务器名;uid=用户名;pwd=密码;database=数据库名");
mycon.Open();
\\如果SQL语句是Select ...
SqlDataAdapter myda=new SqlDataAdapter(SQL语句,mycon);
myda.Fill(myset);
this.DataGrid1.DataSource=myset.Tables[0].DefaultView;
\\如果SQL语句是Delete、Update、Insert
SqlComman cmd=new SqlCommand();
cmd.CommandText=SQL语句;
cmd.CommandType=System.Data.CommandType.Text;
cmd.Connection=mycon;
cmd.ExcuteNoQuery();
mycon.Close();
C#数据库操作的三种经典
用法
.txt
1. 创建
一个
`
Sql
Command
`对象,并将其`CommandType`设置为`CommandType.StoredProcedure`。 2. 通过`ExecuteNonQuery()`方法执行存储过程。 3. 如果需要传递参数,可以在创建`
Sql
Command
`对象后添加参数。 #### 三...
c#数据库操作的3种典型
用法
sql
Command
.Connection =
sql
Connection
;
sql
Command
.CommandText =
sql
SelectCommand;
sql
Connection
.Open();
Sql
Data
Reader
sql
Data
Reader =
sql
Command
.ExecuteReader(); while...
VB连接
SQL
实列(3) !!!!
你可以创建
一个
`
Sql
Command
`对象,设置其`CommandText`属性为
SQL
语句,然后将其`Connection`属性设置为之前创建的`
Sql
Connection
`对象: ```vbnet Dim command As New
Sql
Command
("SELECT * FROM TableName", ...
sql
.zip_C#连接
sql
然后,我们可以创建
一个
Sql
Connection
对象,并使用Open()方法打开连接: ```csharp using (
Sql
Connection
connection = new
Sql
Connection
(connectionString)) { connection.Open(); } ``` 接着,执行
SQL
语句通常...
asp.net
Sql
Data
Adapter
对象使用札记
Sql
Data
Adapter
Sql
Connection
nwindConn = new
Sql
Connection
(“
Data
Source=localhost;Integrated Security=SSPI;Initial Catalog=northwind”);
Sql
Command
selectCMD = new
Sql
Command
(“SELECT CustomerID, ...
C#
111,098
社区成员
642,554
社区内容
发帖
与我相关
我的任务
C#
.NET技术 C#
复制链接
扫一扫
分享
社区描述
.NET技术 C#
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
让您成为最强悍的C#开发者
试试用AI创作助手写篇文章吧
+ 用AI写文章