c#连接数据库全集---实例
来源:互联网 发布:宿迁12345网络问政一把 编辑:程序博客网 时间:2024/04/27 18:04
string strcon;
ConnectionStringSettingsCollection connectionStrings = WebConfigurationManager.ConnectionStrings as ConnectionStringSettingsCollection;
strcon = connectionStrings["tscreenConnectionString"].ToString();
SqlConnection mysql = new SqlConnection(strcon);
mysql.Open();
SqlCommand mytable = new SqlCommand("select * from semsuser", mysql);
SqlDataReader myread = mytable.ExecuteReader();
// myread.Read();
String name;
string userid;
while (myread.Read())
...{
name = myread.GetValue(2).ToString().Trim();
//userid = System.Convert.ToString (Session["user_id"].ToString());
//userid=System.Convert.ToString(Request.Params["user_id"].ToString());
userid = System.Convert.ToString(myread.GetOrdinal("user_id"));
TextBox1.Text = TextBox1.Text + name;
}
userid = Request.Params["user_id"];
TextBox1.Text = TextBox1.Text + userid;
myread.Close();
mytable.Dispose();
mysql.Close();
Response.Redirect("main.aspx");
//********************************************************************************
*********************delect、insert、update、select data control//
string strcon;
ConnectionStringSettingsCollection connectionStrings = WebConfigurationManager.ConnectionStrings as ConnectionStringSettingsCollection;
strcon = connectionStrings["ConnectionString"].ToString();
SqlConnection mysql = new SqlConnection(strcon);
mysql.Open();
SqlCommand mytable = new SqlCommand("select top 10 * from gulou",mysql);
SqlDataReader myread = mytable.ExecuteReader();
myread.Read();
String name;
name = myread.GetValue(5).ToString().Trim();
TextBox1.Text = name;
mytable.Dispose();
mysql.Close();
myread.Close();
//再次查询数据
mytable.CommandText = "select top 1 * from gulou";
mytable.Connection = mysql;
mysql.Open();
SqlDataReader rd = mytable.ExecuteReader();
rd.Read();
name = rd.GetValue(5).ToString().Trim();
TextBox1.Text = TextBox1.Text+"前面与后面" + name;
mytable.Dispose();
mysql.Close();
rd.Close();
TextBox2.Text = TextBox2.Text + "select sucess,";
//插入数据
mysql.Open();
SqlCommand mycomm1 = new SqlCommand();
mycomm1.Connection = mysql;
SqlTransaction trans1 = mysql.BeginTransaction();
mycomm1.Transaction = trans1;
mycomm1.CommandText = "insert into id(id,id_in) values(" + "'叶里瑜'" + ",3)";
mycomm1.ExecuteNonQuery();
trans1.Commit();
mycomm1.Dispose();
mysql.Close();
TextBox2.Text = TextBox2.Text + "insert sucess,";
//更新数据
mysql.Open();
SqlCommand mycommup = new SqlCommand();
mycommup.Connection = mysql;
SqlTransaction transup = mysql.BeginTransaction();
mycommup.Transaction = transup;
mycommup.CommandText = "update id set id=" + "'我用c#插入的'" + "where id_in<>3";
mycommup.ExecuteNonQuery();
transup.Commit();
mycommup.Dispose();
mysql.Close();
TextBox2.Text = TextBox2.Text + "update sucess,";
//删除数据
mysql.Open();
SqlCommand mydel = new SqlCommand();
mydel.Connection = mysql;
SqlTransaction trandel = mysql.BeginTransaction();
mydel.Transaction = trandel;
mydel.CommandText = "delete from id where id_in =1";
mydel.ExecuteNonQuery();
trandel.Commit();
mydel.Dispose();
mysql.Close();
TextBox2.Text =TextBox2.Text + "delete sucess.";
ConnectionStringSettingsCollection connectionStrings = WebConfigurationManager.ConnectionStrings as ConnectionStringSettingsCollection;
strcon = connectionStrings["tscreenConnectionString"].ToString();
SqlConnection mysql = new SqlConnection(strcon);
mysql.Open();
SqlCommand mytable = new SqlCommand("select * from semsuser", mysql);
SqlDataReader myread = mytable.ExecuteReader();
// myread.Read();
String name;
string userid;
while (myread.Read())
...{
name = myread.GetValue(2).ToString().Trim();
//userid = System.Convert.ToString (Session["user_id"].ToString());
//userid=System.Convert.ToString(Request.Params["user_id"].ToString());
userid = System.Convert.ToString(myread.GetOrdinal("user_id"));
TextBox1.Text = TextBox1.Text + name;
}
userid = Request.Params["user_id"];
TextBox1.Text = TextBox1.Text + userid;
myread.Close();
mytable.Dispose();
mysql.Close();
Response.Redirect("main.aspx");
//********************************************************************************
*********************delect、insert、update、select data control//
string strcon;
ConnectionStringSettingsCollection connectionStrings = WebConfigurationManager.ConnectionStrings as ConnectionStringSettingsCollection;
strcon = connectionStrings["ConnectionString"].ToString();
SqlConnection mysql = new SqlConnection(strcon);
mysql.Open();
SqlCommand mytable = new SqlCommand("select top 10 * from gulou",mysql);
SqlDataReader myread = mytable.ExecuteReader();
myread.Read();
String name;
name = myread.GetValue(5).ToString().Trim();
TextBox1.Text = name;
mytable.Dispose();
mysql.Close();
myread.Close();
//再次查询数据
mytable.CommandText = "select top 1 * from gulou";
mytable.Connection = mysql;
mysql.Open();
SqlDataReader rd = mytable.ExecuteReader();
rd.Read();
name = rd.GetValue(5).ToString().Trim();
TextBox1.Text = TextBox1.Text+"前面与后面" + name;
mytable.Dispose();
mysql.Close();
rd.Close();
TextBox2.Text = TextBox2.Text + "select sucess,";
//插入数据
mysql.Open();
SqlCommand mycomm1 = new SqlCommand();
mycomm1.Connection = mysql;
SqlTransaction trans1 = mysql.BeginTransaction();
mycomm1.Transaction = trans1;
mycomm1.CommandText = "insert into id(id,id_in) values(" + "'叶里瑜'" + ",3)";
mycomm1.ExecuteNonQuery();
trans1.Commit();
mycomm1.Dispose();
mysql.Close();
TextBox2.Text = TextBox2.Text + "insert sucess,";
//更新数据
mysql.Open();
SqlCommand mycommup = new SqlCommand();
mycommup.Connection = mysql;
SqlTransaction transup = mysql.BeginTransaction();
mycommup.Transaction = transup;
mycommup.CommandText = "update id set id=" + "'我用c#插入的'" + "where id_in<>3";
mycommup.ExecuteNonQuery();
transup.Commit();
mycommup.Dispose();
mysql.Close();
TextBox2.Text = TextBox2.Text + "update sucess,";
//删除数据
mysql.Open();
SqlCommand mydel = new SqlCommand();
mydel.Connection = mysql;
SqlTransaction trandel = mysql.BeginTransaction();
mydel.Transaction = trandel;
mydel.CommandText = "delete from id where id_in =1";
mydel.ExecuteNonQuery();
trandel.Commit();
mydel.Dispose();
mysql.Close();
TextBox2.Text =TextBox2.Text + "delete sucess.";
- c#连接数据库全集---实例
- jsp连接数据库全集
- C# 连接ACCESS数据库代码实例
- C#连接Access2007数据库代码实例完整版
- C#连接Access数据库实例代码讲解
- C# 连接SQL2008 数据库实例 记录
- C#连接各种数据库语句(实例)
- C#连接Access2007数据库代码实例完整版
- C# 连接ACCESS数据库代码实例
- C# 连接ACCESS数据库代码实例
- C#连接Access数据库字符串的实例
- ADO连接各种数据库的字符串全集
- asp.net连接access数据库之c#篇 实例
- C#连接SQL Server数据库实例代码讲解
- C#连接数据库sqlserver2005,并执行sql语句实例
- C#连接数据库sqlserver2005,执行存储过程的实例
- C#连接数据库sqlserver2005,执行存储过程的实例
- 关于C# Ado.NET连接数据库操作基本实例模板
- 改变
- Jdbc的使用
- birt使用经验
- 有C#来实现WEB服务器的应用分析
- 利用Command模式实现无限次数的Undo/Redo功能
- c#连接数据库全集---实例
- 如何搭建编写Filter的编译环境
- 获取父页面URL的参数对应值及左对齐字符
- Oracle10g 外部表
- D字头火车票 提前20天就可以买到
- response.sendRedirect的注意事项
- struts+spring+hibernate的web应用 架构搭建
- struts+spring+hibernate的web应用 Dao层代码编写
- oracle常用经典SQL查询