日期:2014-05-18 浏览次数:20555 次
public DataTable GetDataTable(string sql) { SQLConnection conn = new OleDbConnection(@"连接字符串"); SQLDbDataAdapter SQLda = new OleDbDataAdapter(sql, conn); DataTable dt = new DataTable(); SQLda.Fill(dt); return dt; }
------解决方案--------------------
string ConStr = "Persist Security Info=False;Initial Catalog=FilmManger;"; ConStr += "Data Source=.;Integrated Security=SSPI;";//连接串不懂自己去看。 SqlConnection myCon = new SqlConnection(ConStr); string ComStr = "select EmployeeID,Name,Sex,Age,Address,Tile from employee"; SqlCommand myCom = new SqlCommand(ComStr, myCon); SqlDataAdapter myDA = new SqlDataAdapter(); myDA.SelectCommand = myCom; myCon.Open(); DataSet myDS = new DataSet(); myDA.Fill(myDS, "employee"); DataView myDV = myDS.Tables["employee"].DefaultView; myDV.Sort = "age"; this.GridView1.DataSource = myDV; this.GridView1.DataBind(); myCon.Close();
------解决方案--------------------
去下载dbhelper数据操作类!都写好的
------解决方案--------------------
private static SqlConnection GetConnection() { string myStr = ConfigurationManager.ConnectionStrings["ConnectionString"].ToString(); SqlConnection myConn = new SqlConnection(myStr); return myConn; } try { SqlConnection myConn = GetConnection(); myConn.Open(); SqlCommand myComm_1 = new SqlCommand(sqlstr_1, myConn); SqlCommand myComm_2 = new SqlCommand(sqlstr_2, myConn); myComm_1.ExecuteNonQuery(); myComm_2.ExecuteNonQuery(); myConn.Close(); flag = true; } catch (Exception ex) { logger.Error(ex); throw; }