private void GetDataByParmSqlCommand()\x0d\x0a{\x0d\x0aSqlConnection sqlc = new SqlConnection(DBUtility.SqlHelper.ConnectionStringLocalTransaction) //取连接
字符串饼建立sqlconnection\x0d\x0atry\x0d\x0a{\x0d\x0a\x0d\x0asqlc.Open()\x0d\x0aSqlCommand com = new SqlCommand("select * from c6 where usr_id = usr_id", sqlc)\x0d\x0aSqlParameter parm = new SqlParameter()\x0d\x0aparm.ParameterName = "@usr_id"\x0d\x0aparm.Value = "01\x0d\x0acom.Parameters.Add(parm)\x0d\x0acom.ExecuteNonQuery()\x0d\x0aDataSet ds = new DataSet()\x0d\x0aSqlDataAdapter sda = new SqlDataAdapter(com)\x0d\x0asda.Fill(ds, "c6")\x0d\x0aDataTable dt = ds.Tables[0]\x0d\x0atextbox.Text ="用户代码:"+ dt.Rows[0]["usr_id"].ToString().Trim() +"用户名称:"+ dt.Rows[0]["usr_name"].ToString().Trim() \x0d\x0a//这样组合一下就可以了,看你要显示哪些信息\x0d\x0a\x0d\x0a}\x0d\x0acatch (Exception ee)\x0d\x0a{\x0d\x0aMessageBox.Show(ee.Message, "")\x0d\x0a}\x0d\x0afinally\x0d\x0a{\x0d\x0asqlc.Close()\x0d\x0a}\x0d\x0a}textbox获取
数据库中的数据
1.连接数据库
:连接字符串(Oracel10g)
Data
Source=(
DESCRIPTION
=(ADDRESS=(PROTOCOL=TCP)(HOST=
localhost
)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=exam)))User
ID=systemPassword=systemUnicode=True
2.要想获取数据库中自定表的数据sql
3.
运行sql
4.根据运行的结果绑定到textbox中
评论列表(0条)