当前位置: 代码迷 >> ASP.NET >> 求数据库查询代码,该如何解决
  详细解决方案

求数据库查询代码,该如何解决

热度:4231   发布时间:2013-02-25 00:00:00.0
求数据库查询代码
会员姓名
原卡号
旧卡号
密码
查询
C#的,应该连接数据库再写查询语句吧,就是不会写连接数据库的代码,没头绪,大家帮忙,好吧
namespace MASTER_ANCN
{
  public partial class Form1 : Form
  {
  public Form1()
  {
  InitializeComponent();
  }

  private void btnsearch_Click(object sender, EventArgs e)
  {
  using System. date.SQLClient;
  SQLConnection SQLConn = new Connection();
  string sql=Select *From ;
  SQLConn. ConnectionString="myconnectionstring";
  SQLConn. open();

  }
  }
}
应该缺了很多东西,不知道该怎么写了,不会


------解决方案--------------------------------------------------------
C# code
   public DataTable GetDataTable(string sql)        {                      SQLConnection conn = new OleDbConnection(@"连接字符串");            SQLDbDataAdapter SQLda = new OleDbDataAdapter(sql, conn);            DataTable dt = new DataTable();            SQLda.Fill(dt);            return dt;                }
------解决方案--------------------------------------------------------
探讨
给我也不知道怎么改啊
怎么加啊
哎,基础太差啊

------解决方案--------------------------------------------------------
private static DataSet SelectRows(DataSet dataset,
string connectionString,string queryString) 
{
using (SqlConnection connection = 
new SqlConnection(connectionString))
{
SqlDataAdapter adapter = new SqlDataAdapter();
adapter.SelectCommand = new SqlCommand(
queryString, connection);
adapter.Fill(dataset);
return dataset;
}
}
楼主买本书,好好看看吧
------解决方案--------------------------------------------------------
C# code
        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数据操作类!都写好的
------解决方案--------------------------------------------------------
C# code
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;            }
  相关解决方案