SqlCommand是C#中与Sql数据库打交道的对象,几乎所有的Sql数据库操作都需要使用该对象来实现,但其功能有限,只是简单的实现了与Sql数据库的接口而已;
//以下使用陈述式写法 听说可以 自动生成 try,finally功能
using (SqlConnection connection = new SqlConnection(connectString))
{
using (SqlCommand command = new SqlCommand())
{
command.Connection = connection;
command.CommandType = CommandType.Text;
command.CommandText = "INSERT into [dbo].[Table_Friber_SN] (Friber_SN, SN, note, OP) VALUES (@Friber_SN, @SN, @note, @OP)";
command.Parameters.AddWithValue("@Friber_SN", LblNewSN.Text);
command.Parameters.AddWithValue("@SN", (int)DS.Rows[0][0] + 1);
command.Parameters.AddWithValue("@note", "新增SN");
command.Parameters.AddWithValue("@OP", TxtOP.Text);
connection.Open();
int recordsAffected = command.ExecuteNonQuery();
LblReturn.Text = recordsAffected.ToString();
LblC9C12.Text = "xxxx";
}
}
adapter的定义是基於command的,当然也可以之间在定义adapter的时候写入sql语句和connection对象
// 连线str
string connectString = "Server=dataserver; Database=FormericaOE; User ID=xxx; Password=xxx; ";
// 建构 sqlConnection连线物件
SqlConnection conn = new SqlConnection(connectString);
string selectstr = "SELECT MAX(SN)" + "FROM[FormericaOE].[dbo].[Table_Friber_SN]";
SqlDataAdapter da = new SqlDataAdapter(selectstr, connectString);
DS.Clear(); //先清空 DataTable
da.Fill(DS); //用SqlDataAdapter 填入 DS
可以这样理解: DataSet用来装表的集合,里面可以装从SqlDataAdapter中返回的一系列的DataTable
如果返回的有多张表,那麽我们可以通过索引的方式来找到想要的表:
DataTable dt = ds.Tables[0];或DataTable dt = ds.Tables["products"];
DataSet可以直接做爲数据控件的数据源,也可以从中获取表或表的视图来做爲数据源.如:
<<: 爬虫怎麽爬 从零开始的爬虫自学 DAY30 铁人赛完赛心得
>>: Day-29 请说明 RDBMS 和 NOSQL 是什麽?
常常有时候在阅读较大的专案时 没有定位档案位置的功能的话很难找到该 Class 的位置 大家可以找到...
记得我第一次正式的串接API的时候,踏着愉悦的心想说自己要成为一个真正的前端要来串接了~~~ 结果写...
亲爱的小四用户您好,心动年代目前更新中,请耐心等候... 30分钟後... 亲爱的小四用户您好,心动...
:D 这个部分的概念,其实跟把训练好的模型还有过程的Loss value、Metrics v...
透过 audio tag 设定背景音乐 class BGM { constructor() { th...