private void lc(object sender, MouseEventArgs e) { c.Open(); DataSet ds = new DataSet(); string query = "select ID,pname,bill,pbill from pdetails where [email protected] "; OleDbCommand cmd = new OleDbCommand(query, c); cmd.Parameters.Add("@bc", OleDbType.Date).Value = dateTimePicker1.Value.Date; OleDbDataReader dr = cmd.ExecuteReader(); DataTable dt = new DataTable(); dt.Load(dr); /*ds.Tables.Add(dt); OleDbDataAdapter da = new OleDbDataAdapter(); da.Fill(dt);*/ dataGridView1.DataSource = dt.DefaultView; c.Close(); try { c.Open(); String str = @"SELECT SUM(pbill) FROM pdetails WHERE [email protected];"; OleDbCommand comm2 = new OleDbCommand(str, c); comm2.Parameters.Add("@bb", OleDbType.Date).Value = dateTimePicker1.Value.Date; bill = Convert.ToDouble(comm2.ExecuteScalar()); label3.Text = bill.ToString() + "/-"; } catch(Exception ex) { MessageBox.Show("selected date miss match"); c.Close(); } c.Close(); }
protected void Page_Load(object sender, EventArgs e)
{
System.Data.OleDb.OleDbConnection conn = new System.Data.OleDb.OleDbConnection();
string sql = "";
string connstring [email protected]"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\DropBox\My Dropbox\Devry\CIS407\SU10B\day8\mobileweb1\NorthWind.mdb;";
System.Data.OleDb.OleDbDataReader dr;
System.Data.OleDb.OleDbCommand comm = new System.Data.OleDb.OleDbCommand();
//get this from connectionstrings.com/access
conn.ConnectionString = connstring;
conn.Open();
//here I can talk to my db...
comm.Connection = conn;
//Console.WriteLine(conn.State);
sql = "select categoryid, categoryname from categories";
comm.CommandText = sql;
dr = comm.ExecuteReader();
rptCategory.DataSource = dr;
rptCategory.DataBind();
dr.Close();
//Console.WriteLine(conn.State);
sql = "select supplierid, companyname from suppliers";
comm.CommandText = sql;
dr = comm.ExecuteReader();
rptSupplier.DataSource = dr;
rptSupplier.DataBind();
}
protected void LoadData() { string strsql = "select * from customers where custnumber = " + Session["custid"]; OleDbConnection myConn = new OleDbConnection(); myConn.ConnectionString = System.Web.Configuration.WebConfigurationManager. ConnectionStrings["AcmeShoppeConnectionString"].ConnectionString; OleDbCommand myCmd = new OleDbCommand(strsql, myConn); OleDbDataReader myReader; if (myConn.State == ConnectionState.Closed) myConn.Open(); myReader = myCmd.ExecuteReader(); if (myReader.HasRows) { myReader.Read(); this.lblFName.Text = myReader["FirstName"].ToString(); this.lblLName.Text = myReader["LastName"].ToString(); this.txtAddress.Text = myReader["Address"].ToString(); this.txtCity.Text = myReader["City"].ToString(); this.txtZip.Text = myReader["ZipCode"].ToString(); this.DropDownList1.SelectedValue = myReader["State"].ToString(); } else this.lblerr.Text = "error"; myReader.Close(); myCmd.CommandText = "select sum(extension) from cart_view01 " + "where cartnumber = " + Session["cartnumber"]; decimal decSubtotal = 0; double decSalesTax = 0; double decTotal = 0; double decShip = 3.25; if (myConn.State == ConnectionState.Closed) myConn.Open(); myReader = myCmd.ExecuteReader(); if (myReader.HasRows) { myReader.Read(); if (myReader[0] != DBNull.Value) { decSubtotal = Convert.ToDecimal(myReader[0].ToString()); this.lblSubtotal.Text = decSubtotal.ToString("c"); } decSalesTax = Convert.ToDouble(decSubtotal) * .05; Math.Round(decSalesTax, 2); decTotal = Convert.ToDouble(decSubtotal) + decSalesTax + decShip; Math.Round(decTotal, 2); this.lblTax.Text = decSalesTax.ToString("c"); this.lblTotal.Text = decTotal.ToString("c"); this.lblShipping.Text = decShip.ToString("c"); } else this.lblerr.Text = "error"; myConn.Close(); }
private void Guncelle() { using (OleDbConnection conn = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=hesap.mdb")) { conn.Open(); OleDbCommand komut = new OleDbCommand(); komut.Connection = conn; komut.CommandText = "Select * from hesap"; // sorgu / komut cumlemi yazıyorum. komut.ExecuteNonQuery(); // insert , updateiçin gerekli satir sayisi donduruyoruz. OleDbDataReader dr = komut.ExecuteReader(); // datareader olusturup komut sorgulayıp veritabaninda okuma işlemini tanıtıyoruz while (dr.Read()) // datareader ile okuyoruz. { string hadi = dr["hadi"].ToString(); string kadi = dr["kadi"].ToString(); string q; using (WebClient asd = new WebClient()) { asd.Encoding = Encoding.UTF8; q = asd.DownloadString("http://gdata.youtube.com/feeds/api/users/" + kadi + "/uploads?v=2&alt=jsonc&max-results=0"); } string[] adet1 = q.Split(new string[] { "totalItems\":" }, StringSplitOptions.None); string[] adet2 = adet1[1].Split(','); listView1.Items.Add(new ListViewItem(new string[] { hadi, "Adet: "+adet2[0] })); } dr.Close(); komut.ExecuteNonQuery(); // insert , updateiçin gerekli satir sayisi donduruyoruz. dr = komut.ExecuteReader(); // datareader olusturup komut sorgulayıp veritabaninda okuma işlemini tanıtıyoruz while (dr.Read()) // datareader ile okuyoruz. { string kadi = dr["hadi"].ToString(); // veritabanimdaki "kadi" alanımdaki veriyi alip kadi değişkenine atıyorum(yukarıda string olusturmustum) string sifre = dr["hsifresi"].ToString(); // aynı durum söz konusu string devkey = dr["devkey"].ToString(); Random a = new Random(); string id = a.Next(100000, 999999).ToString(); YouTubeRequestSettings settings = new YouTubeRequestSettings(id, devkey, kadi,sifre); YouTubeRequest request = new YouTubeRequest(settings); string feedUrl = "https://gdata.youtube.com/feeds/api/users/default/uploads"; Feed<Video> videoFeed = request.Get<Video>(new Uri(feedUrl)); foreach (Video entry in videoFeed.Entries) { string vid_thumb ="http://img.youtube.com/vi/"+entry.VideoId+"/0.jpg"; int izlenme = entry.ViewCount; if(izlenme == -1) izlenme = 0; listView1.Items.Add(new ListViewItem(new string[] { kadi,entry.YouTubeEntry.Title.Text,izlenme.ToString() })); } } } }
protected void btnLogin_Click(object sender, EventArgs e) { string strsql = "select [CustNumber], [Email], [PWD] from customers"; OleDbConnection myConn = new OleDbConnection(); myConn.ConnectionString = System.Web.Configuration.WebConfigurationManager. ConnectionStrings["AcmeShoppeConnectionString"].ConnectionString; OleDbCommand myCmd = new OleDbCommand(strsql, myConn); OleDbDataReader myReader; if (myConn.State == ConnectionState.Closed) myConn.Open(); myReader = myCmd.ExecuteReader(); DataTable dataTable = new DataTable(); dataTable.Load(myReader); int rowCount = rowCount = dataTable.Rows.Count; myReader = myCmd.ExecuteReader(); int i = 0; if (myReader.HasRows) { while (i < rowCount) { myReader.Read(); string strId = this.txtUser.Text; string strPwd = this.txtPass.Text; string memId = myReader["Email"].ToString(); string memPwd = myReader["PWD"].ToString(); if (strId == memId && strPwd == memPwd) { FormsAuthentication.RedirectFromLoginPage(strId, false, strPwd); string custid = myReader["CustNumber"].ToString(); Session["custid"] = custid; Session["userid"] = memId; break; } else if (strId == "admin" && strPwd == "admin") { FormsAuthentication.RedirectFromLoginPage(strId, false, strPwd); break; } i++; } if (i == rowCount) this.lblmessage.Text = "User Does not exist!"; } }
public static Dictionary<string, Dictionary<string, object>> GetStatistics() { Dictionary<string, Dictionary<string, object>> list = new Dictionary<string, Dictionary<string, object>>(); string strConnection = "provider=Microsoft.ACE.OLEDB.12.0;Data Source=Battleship.accdb;"; string strSQL = ""; OleDbConnection myConnection = new OleDbConnection(strConnection); OleDbCommand myCommand = new OleDbCommand(strSQL, myConnection); try { myConnection.Open(); strSQL = "SELECT Name, Min(Turns), Count(*) FROM Statistic WHERE IsWinner GROUP BY Name ORDER BY Name"; myCommand.CommandText = strSQL; myCommand.CommandType = System.Data.CommandType.Text; OleDbDataReader reader = myCommand.ExecuteReader(); while (reader.Read()) { Dictionary<string, object> fields = new Dictionary<string, object>(); fields["Turns"] = reader.GetInt32(1).ToString(); fields["Wins"] = reader.GetInt32(2).ToString(); fields["Loses"] = 0; list[reader.GetString(0)] = fields; } reader.Close(); strSQL = "SELECT Name, Count(*) FROM Statistic WHERE NOT IsWinner GROUP BY Name ORDER BY Name"; myCommand.CommandText = strSQL; myCommand.CommandType = System.Data.CommandType.Text; reader = myCommand.ExecuteReader(); while (reader.Read()) { if (!list.ContainsKey(reader.GetString(0))) { Dictionary<string, object> fields = new Dictionary<string, object>(); fields["Turns"] = "DNA"; fields["Wins"] = 0; list[reader.GetString(0)] = fields; } list[reader.GetString(0)]["Loses"] = reader.GetInt32(1).ToString(); } reader.Close(); } catch (Exception ex) { Console.WriteLine("Error: " + ex.Message); } myConnection.Close(); return list; }
/// <summary> /// Reads the selected file and places the contents into a DataTable. /// </summary> /// <returns>Datatable of students in file</returns> public DataTable ReadFile() { DataTable data = new DataTable(); try { using (cmd = con.CreateCommand()) { cmd.CommandText = string.Format("SELECT * from [{0}]", file.Name); con.Open(); using (dr = cmd.ExecuteReader()) { data.Load(dr); } } } catch (OleDbException oExe) { Debug.WriteLine(oExe.Message); } finally { con.Close(); } return data; }
protected void datefilterPlanMeal_DayRender(object sender, DayRenderEventArgs e) { OleDbCommand command = new OleDbCommand("SELECT * FROM PlannedMeal WHERE UserDataID = " + userID + " ORDER BY CreatedDate DESC", myConnection); OleDbDataReader dr = command.ExecuteReader(); // Read DataReader till it reaches the end while (dr.Read() == true) { // Assign the Calendar control dates // already contained in the database //datefilterPlanMeal.SelectedDates.Add((DateTime)dr["CreatedDate"]); if (e.Day.Date == (DateTime)dr["CreatedDate"]) { e.Cell.BackColor = System.Drawing.Color.Silver; } } if (e.Day.IsSelected) { e.Cell.BackColor = System.Drawing.ColorTranslator.FromHtml("#4db6ac"); e.Cell.ForeColor = System.Drawing.Color.White; } // Close DataReader dr.Close(); }
private void fill_form(string p_id) { String strQuery = String.Empty; OleDbConnection sqlConn = new OleDbConnection(); OleDbCommand sqlComm = new OleDbCommand(); OleDbDataReader sqlRead;// = new OleDbDataReader(); DateTime strReturn = DateTime.Now; // sqlConn.ConnectionString = PCPUB.m_oledb_connection.ToString(); sqlConn.Open(); // strQuery = String.Empty; strQuery += " SELECT"; strQuery += " [yarn_count_id],"; strQuery += " [yarn_count_name]"; strQuery += " FROM [tis_yarn_count]"; strQuery += " WHERE [yarn_count_id] = '" + p_id + "'"; // sqlComm.Connection = sqlConn; sqlComm.CommandText = strQuery.ToString(); sqlRead = sqlComm.ExecuteReader(); // if (sqlRead.Read()) { txt_yarn_count_id.Text = sqlRead["yarn_count_id"].ToString(); txt_yarn_count_name.Text = sqlRead["yarn_count_name"].ToString(); } // sqlRead.Close(); sqlConn.Close(); sqlRead.Dispose(); sqlComm.Dispose(); sqlConn.Dispose(); }
public DataTable sepetcevir(string uyeID, string map) { OleDbConnection cnn = new OleDbConnection("Provider=Microsoft.Jet.Oledb.4.0; Data Source=" + map); cnn.Open(); OleDbCommand cmd = new OleDbCommand("select sepet from uyeler where uyeid=" + uyeID, cnn); OleDbDataReader rdr = cmd.ExecuteReader(); rdr.Read(); string[] urunler = rdr[0].ToString().Split(','); DataTable dt = new DataTable(); dt.Columns.AddRange(new DataColumn[3] { new DataColumn("fid"), new DataColumn("aciklama"), new DataColumn("fiyat") }); if (rdr[0].ToString() != "") { foreach (string item in urunler) { cmd.Dispose(); string fid = item; cmd = new OleDbCommand("select * from fotolar where fot_id=" + fid, cnn); OleDbDataReader rdr2 = cmd.ExecuteReader(); rdr2.Read(); string ack = rdr2[5].ToString(); string fiyat = rdr2[6].ToString(); dt.Rows.Add(fid, ack, fiyat); } } cnn.Close(); return dt; }
protected void Button1_Click(object sender, EventArgs e) { int lgflg = 0; OleDbConnection conn = new OleDbConnection(ConfigurationSettings.AppSettings["classDB"]); OleDbCommand cmd = new OleDbCommand("SELECT * FROM student WHERE studentpassword = '" + password.Text + "' AND email = '" + userName.Text + "'", conn); conn.Open(); OleDbDataReader myReader = cmd.ExecuteReader(); while (myReader.Read()) { lgflg = 1; Session.Add("fname", myReader["Contact_name"]); Session.Add("address", myReader["address"]); Session.Add("city", myReader["city"]); Session.Add("state", myReader["state"]); Session.Add("zipcode", myReader["zipcode"]); } myReader.Close(); conn.Close(); if (lgflg == 1) { Response.Write(Session["fname"]); } else { error.Visible = true; } }
public Window_jianzhan4() { InitializeComponent(); systime.Content = DateTime.Now.ToShortTimeString(); OleDbDataReader dr; OleDbConnection conn = new OleDbConnection(odbcConnStr); string sql = "select * from rearview_checking"; OleDbCommand cmd = new OleDbCommand(sql, conn); conn.Open(); dr = cmd.ExecuteReader(); if (dr.Read()) { string s; double t,k; station_point.Content = dr.GetString(1).ToString(); rearview_point.Content = dr.GetString(2).ToString(); BS.Content = dr.GetString(3).ToString(); s = BS.Content.ToString(); t = Convert.ToDouble(s); Random ran = new Random(); k = ran.Next(0, 200)*0.0001; t = k + t; HA.Content = t.ToString(); dHA.Content = k.ToString(); } conn.Close(); }
//--------------------------------------------------------------------- public static void DatatypeQuery(OleDbConnection dbcon, CodeGenerator cg) { cg.DataTypeList.Clear(); OleDbCommand cmd = new OleDbCommand("SELECT * FROM DataTypes", dbcon); OleDbDataReader dr = cmd.ExecuteReader(); while (dr.Read()) { DataType curDatatype = new DataType(); curDatatype.ID = Convert.ToInt32(dr["ID"].ToString()); curDatatype.DataTypeName = dr["DataTypeName"].ToString(); curDatatype.CType = dr["CType"].ToString(); curDatatype.CTypeDef = dr["CTypeDef"].ToString(); curDatatype.CSType = dr["CSType"].ToString(); curDatatype.CSTypeDef = dr["CSTypeDef"].ToString(); curDatatype.VBType = dr["VBType"].ToString(); curDatatype.VBTypeDef = dr["VBTypeDef"].ToString(); curDatatype.PythonType = dr["PythonType"].ToString(); curDatatype.PythonTypeDef = dr["PythonTypeDef"].ToString(); cg.DataTypeList.Add(curDatatype); } dr.Close(); }
//--------------------------------------------------------------------- public static void ConstantQuery(OleDbConnection dbcon, CodeGenerator cg) { cg.ConstantList.Clear(); OleDbCommand cmd = new OleDbCommand("SELECT * FROM Constants ORDER BY Topic, ID", dbcon); OleDbDataReader dr = cmd.ExecuteReader(); while (dr.Read()) { Constant curConst = new Constant(); curConst.Name = dr["Name"].ToString(); curConst.Value = dr["Value"].ToString(); Int32 nTopic = Convert.ToInt32(dr["Topic"].ToString()); if (nTopic > 0) { curConst.Topic = cg.TopicList[nTopic - 1].Name.ToString(); } else { curConst.Topic = ""; } curConst.Description = dr["Description"].ToString(); cg.ConstantList.Add(curConst); //curConst.Print(); } dr.Close(); }
public static int Roles_CreateRole (DbConnection connection, string applicationName, string rolename) { string appId = (string) DerbyApplicationsHelper.Applications_CreateApplication (connection, applicationName); if (appId == null) return 1; string querySelect = "SELECT RoleName FROM aspnet_Roles WHERE ApplicationId = ? AND LoweredRoleName = ?"; OleDbCommand cmdSelect = new OleDbCommand (querySelect, (OleDbConnection) connection); AddParameter (cmdSelect, "ApplicationId", appId); AddParameter (cmdSelect, "LoweredRoleName", rolename.ToLowerInvariant ()); using (OleDbDataReader reader = cmdSelect.ExecuteReader ()) { if (reader.Read ()) return 2; // role already exists } string queryInsert = "INSERT INTO aspnet_Roles (ApplicationId, RoleId, RoleName, LoweredRoleName) VALUES (?, ?, ?, ?)"; OleDbCommand cmdInsert = new OleDbCommand (queryInsert, (OleDbConnection) connection); AddParameter (cmdInsert, "ApplicationId", appId); AddParameter (cmdInsert, "RoleId", Guid.NewGuid ().ToString ()); AddParameter (cmdInsert, "RoleName", rolename); AddParameter (cmdInsert, "LoweredRoleName", rolename.ToLowerInvariant ()); cmdInsert.ExecuteNonQuery (); return 0; }
public void FillCombo() { try { con = new OleDbConnection(cs); con.Open(); string ct = "select RTRIM(CategoryName) from Category order by CategoryName"; cmd = new OleDbCommand(ct); cmd.Connection = con; rdr = cmd.ExecuteReader(); while (rdr.Read()) { cmbCategory.Items.Add(rdr[0]); } con.Close(); con = new OleDbConnection(cs); con.Open(); string ct1 = "select RTRIM(CompanyName) from Company order by CompanyName"; cmd = new OleDbCommand(ct1); cmd.Connection = con; rdr = cmd.ExecuteReader(); while (rdr.Read()) { cmbCompany.Items.Add(rdr[0]); } con.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public IDataReader ExecuteDataReader(string connectionString, string query) { _connection = new OleDbConnection(connectionString); _connection.Open(); var command = new OleDbCommand(query, _connection); return command.ExecuteReader(); }
private void LoadItems() { string query = ""; OleDbConnection myConn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("../App_Data/items.mdb")); myConn.Open(); for (int index = 0; index <= 24; index ++) { query = "update Items set Items = rnd() * 10 where Id = " + index.ToString(); OleDbCommand myComm1 = new OleDbCommand(query, myConn); myComm1.ExecuteNonQuery(); query = "update Items set Price = rnd() * 100 where Id = " + index.ToString(); OleDbCommand myComm2 = new OleDbCommand(query, myConn); myComm2.ExecuteNonQuery(); } query = "SELECT Id, Name, Items, Price FROM Items"; OleDbCommand myComm = new OleDbCommand(query, myConn); OleDbDataReader myReader = myComm.ExecuteReader(); gridItems.DataSource = myReader; gridItems.DataBind(); myReader.Close(); }
protected void Page_Load(object sender, System.EventArgs e) { // resolve the address to the Access database string fileNameString = this.MapPath("."); fileNameString += "..\\..\\..\\..\\data\\chartdata.mdb"; // initialize a connection string string myConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=" + fileNameString; // define the database query string mySelectQuery="SELECT GrossSales FROM SALES WHERE QuarterEnding < #01/01/2002#;"; // create a database connection object using the connection string OleDbConnection myConnection = new OleDbConnection(myConnectionString); // create a database command on the connection using query OleDbCommand myCommand = new OleDbCommand(mySelectQuery, myConnection); // open the connection myCommand.Connection.Open(); // create a database reader OleDbDataReader myReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection); // since the reader implements and IEnumerable, pass the reader directly into // the DataBind method with the name of the Column selected in the query Chart1.Series["Default"].Points.DataBindY(myReader, "GrossSales"); // close the reader and the connection myReader.Close(); myConnection.Close(); }
private void button1_Click(object sender, EventArgs e) { string a = Convert.ToString(textBox1.Text); string b = Convert.ToString(textBox2.Text); string queryString = "SELECT * FROM [Admin]"; string connectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\Vladislav\Documents\kursach1.mdb"; OleDbConnection myOleDbConnection = new OleDbConnection(connectionString); OleDbCommand myOleDbCommand = new OleDbCommand(queryString, myOleDbConnection); myOleDbConnection.Open(); OleDbDataReader myOleDbDataReader = myOleDbCommand.ExecuteReader(); while (myOleDbDataReader.Read()) { if (myOleDbDataReader.GetString(0) == a && myOleDbDataReader.GetString(1) == b) { Form6 form6 = new Form6(); form6.Visible = true; this.Visible = false; break; } } myOleDbDataReader.Close(); myOleDbConnection.Close(); }
public void binderStudentInfo(string username) { try { OleDbConnection con=DB.createcon(); OleDbCommand cmd=new OleDbCommand(); cmd.CommandText="select * from [student] where [studentUsername]='"+username+"'"; cmd.Connection=con; con.Open(); OleDbDataReader odr= cmd.ExecuteReader(); while(odr.Read()){ this.userName.Text=username; this.student_name.Value=odr["studentName"].ToString(); //this.student_id.Value = odr["studentID"].ToString(); //this.student_xibie.Value = odr["studentDepartment"].ToString(); // this.student_grate.Value = odr["studentGrade"].ToString(); //this.student_class.Value = odr["studentClass"].ToString(); //this.tel.Value = odr["studentTel"].ToString(); this.qq.Value = odr["studentQQ"].ToString(); this.about.Value = odr["studentAbout"].ToString(); ////this.ChTypeTrainCount.Text=odr["trainChCount"].ToString(); //this.EnTypeTrainCount.Text=odr["trainEnCount"].ToString(); //this.ChypeMatchCount.Text=odr["mathchChCount"].ToString(); //this.EnTypeMatchCount.Text=odr["mathchEnCount"].ToString(); } odr.Close(); con.Close(); } catch (Exception exp) { saveErrorMessage.writeFile("查询学生的个人信息时出错",exp.ToString()); } }
protected void Page_Load(object sender, EventArgs e) { if (!this.IsPostBack) { string name = Request["name"].ToString(); OleDbConnection con = DB.createDB(); con.Open(); OleDbCommand cmd = new OleDbCommand();//声明一个OleDbCommand的 cmd对象,并将其实例化 cmd.Connection = con; cmd.CommandText = "select * from tb_qianfei where name='" + name + "'"; cmd.ExecuteNonQuery(); OleDbDataReader sdr = cmd.ExecuteReader(); sdr.Read(); if (name!= "") { this.lblqfname.Text = sdr.GetString(0).ToString(); this.lblzz.Text = sdr.GetString(1); this.lbllb.Text = sdr.GetString(2); this.lblrqzs.Text = sdr.GetDateTime(3).ToShortDateString(); this.lblzzsj.Text = sdr.GetDateTime(4).ToShortDateString(); this.lblje.Text = sdr.GetString(5).ToString(); this.Lblzt.Text = sdr.GetString(6).ToString(); this.lbljsr.Text = sdr.GetString(7).ToString(); } else { Response.Write("暂无主题,不能显示"); Response.Redirect("Default.aspx");//将该页跳转到指定的页面中 } } }
private void btn_Browser_Click(object sender, EventArgs e) { OpenFileDialog P_open = new OpenFileDialog();//创建打开文件对话框对象 P_open.Filter = "文本文件|*.txt|所有文件|*.*";//设置筛选字符串 if (P_open.ShowDialog() == DialogResult.OK) { txt_Path.Text = P_open.FileName;//显示文件路径 string conn = string.Format(//创建连接字符串 @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Extended Properties=text", P_open.FileName.Substring(0,P_open.FileName.LastIndexOf(@"\"))); OleDbConnection P_OleDbConnection = new OleDbConnection(conn);//创建连接对象 try { P_OleDbConnection.Open();//打开连接 OleDbCommand cmd = new OleDbCommand(//创建命令对象 string.Format("select * from {0}", P_open.FileName.Substring(P_open.FileName.LastIndexOf(@"\"), P_open.FileName.Length - P_open.FileName.LastIndexOf(@"\"))), P_OleDbConnection); OleDbDataReader oda = cmd.ExecuteReader();//得到数据读取器对象 while (oda.Read()) { txt_Message.Text += oda[0].ToString();//得到文本文件中的字符串 } } catch (Exception ex) { MessageBox.Show(ex.Message);//弹出消息对话框 } finally { P_OleDbConnection.Close();//关闭连接 } } }
private bool CheckApologizeExisted() { OleDbConnection Con = ET_Lib.E_trainingConnection; OleDbCommand Cmd = new OleDbCommand("SELECT TRshehId, ApologyDate, ApologyReson FROM DowraApology WHERE (TRshehId = " + ViewState["TRshehId"].ToString() + ")", Con); OleDbDataReader Dr; try { Con.Open(); Dr = Cmd.ExecuteReader(); if (Dr.HasRows) { Dr.Read(); TxtReason.Text = Dr.GetValue(2).ToString(); LblApologizeDate.Text = Convert.ToDateTime(Dr.GetValue(1).ToString()).ToShortDateString().ToString(); Cmd.CommandText = "SELECT DowraName FROM Dowraat WHERE (DowraId = " + Request.QueryString["Courseid"].ToString() + ")"; Dr.Close(); LblCourseName.Text = Cmd.ExecuteScalar().ToString(); Con.Close(); return true; } else { Con.Close(); return false; } } catch (Exception ex) { LblState.Text = ex.Message; LblState.Visible = true; Con.Close(); return false; } }
protected void Page_Load(object sender, EventArgs e) { System.Data.OleDb.OleDbConnection Conn = new System.Data.OleDb.OleDbConnection(); Conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("app_data/productsdb.mdb"); Conn.Open(); //Response.Write(Conn.State); System.Data.OleDb.OleDbCommand Comm = new System.Data.OleDb.OleDbCommand(); System.Data.OleDb.OleDbDataReader dr; Comm.Connection = Conn; Comm.CommandText = "select productid, productname, productiondescription, price, qoh, imagelocation from products"; if (Request.Params["categoryid"] != null && Request.Params["categoryid"].Length >0) { Comm.CommandText += " where categoryid = ?" ; Comm.Parameters.AddWithValue("anything", Request.Params["categoryid"].ToString()); } dr = Comm.ExecuteReader(); bool firstone = true; Response.Write("{\"product\":["); while (dr.Read()) { if (!firstone) { Response.Write(","); } Response.Write(dr[0].ToString()); firstone = false; } Response.Write("]}"); }
private void frmProfil_Load(object sender, EventArgs e)
{
OleDbConnection con = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data source=" + cale + "\\Soft.accdb");
con.Open();
string text = "select* from Utilizatori where [email protected]";//
OleDbCommand com = new OleDbCommand(text, con);
com.Parameters.AddWithValue("Mail", ((Main)this.MdiParent).nume);
OleDbDataReader r = com.ExecuteReader();
while (r.Read())
{
//if(System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable())
//{
// lblPic.ImageLocation = ((Main)this.MdiParent).url + "/img/"+;
//}
//else
//{
if (r["Imagine"].ToString() != "")
{
lblPic.Image = System.Drawing.Image.FromFile(cale + r["Imagine"].ToString());
}
// }
label2.Text = r["Nume"].ToString();
label7.Text = r["Mail"].ToString();
label8.Text = r["Clasa"].ToString();
label9.Text = r["Acces"].ToString();
label10.Text = r["Gen"].ToString();
}
r.Close();
con.Close();
note();
}
//Create an Excel file with 2 columns: name and score: //Write a program that reads your MS Excel file through //the OLE DB data provider and displays the name and score row by row. static void Main() { OleDbConnection dbConn = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;" + @"Data Source=D:\Telerik\DataBases\HW\ADONET\06. ReadExcel\Table.xlsx;Extended Properties=""Excel 12.0 XML;HDR=Yes"""); OleDbCommand myCommand = new OleDbCommand("select * from [Sheet1$]", dbConn); dbConn.Open(); //First way //using (dbConn) - I think it is better to use dbConn in using clause, but for the demo issues i dont use using. //{ OleDbDataReader reader = myCommand.ExecuteReader(); while (reader.Read()) { string name = (string)reader["Name"]; double score = (double)reader["Score"]; Console.WriteLine("{0} - score: {1}", name, score); } //} dbConn.Close(); //Second way dbConn.Open(); Console.WriteLine(); Console.WriteLine("Second Way"); Console.WriteLine("----------"); DataTable dataSet = new DataTable(); OleDbDataAdapter adapter = new OleDbDataAdapter("select * from [Sheet1$]", dbConn); adapter.Fill(dataSet); foreach (DataRow item in dataSet.Rows) { Console.WriteLine("{0}|{1}", item.ItemArray[0], item.ItemArray[1]); } dbConn.Close(); }
public void GetEmailContent(int CategoryID) { OleDbConnection oleDBConnetion = new OleDbConnection(); oleDBConnetion.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" + Server.MapPath("../App_Data/emailclient.mdb") + "; User Id=; Password="; // gets the datasource for the emails list OleDbCommand oleDBCommand = new OleDbCommand(); oleDBCommand.CommandType = CommandType.Text; oleDBCommand.Connection = oleDBConnetion; oleDBCommand.CommandText = "SELECT EmailID, EmailCategoryID, EmailSubject, EmailFrom, EmailContent FROM EmailClient where EmailCategoryID = " + CategoryID + ""; OleDbDataReader dataReader; oleDBConnetion.Open(); dataReader = oleDBCommand.ExecuteReader(); emailList.DataSource = dataReader; emailList.DataBind(); dataReader.Close(); // get the first email from the list for loading it's details OleDbCommand topOleDBCommand = new OleDbCommand(); topOleDBCommand.CommandType = CommandType.Text; topOleDBCommand.Connection = oleDBConnetion; topOleDBCommand.CommandText = "SELECT top 1 EmailID FROM EmailClient where EmailCategoryID = " + CategoryID + ""; OleDbDataReader topDataReader; topDataReader = topOleDBCommand.ExecuteReader(); if (topDataReader.Read()) selectedEmailID = topDataReader.GetInt32(0); topDataReader.Close(); oleDBConnetion.Close(); }
public override List<DomainAlias> GetDomainAliases(string domainName) { var _tmp = new List<DomainAlias>(); using (OleDbConnection _conn = new OleDbConnection(Settings.Default.connectionString)) { _conn.Open(); using (OleDbCommand _cmd = new OleDbCommand(@"SELECT domain_aliases.name AS alias, domains.name AS [domain], domain_aliases.status FROM (domain_aliases INNER JOIN domains ON domain_aliases.dom_id = domains.id) WHERE (domain_aliases.status = 0) AND (domains.name = ?)", _conn)) { _cmd.CommandType = CommandType.Text; _cmd.Parameters.AddWithValue("NAME", domainName); using (OleDbDataReader _read = _cmd.ExecuteReader()) { while (_read.Read()) { var _d = new DomainAlias(); _d.Domain = _read["domain"].ToString(); _d.Alias = _read["alias"].ToString(); _tmp.Add(_d); } } } _conn.Close(); } return _tmp; }
public static void readFromDB(OleDbConnection conn) { string testSelect = " SELECT * FROM ImportAccess"; OleDbCommand comm = new OleDbCommand(testSelect, conn); OleDbDataReader dr = comm.ExecuteReader(); object[] buffer = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; StringBuilder sb = new StringBuilder(); while (dr.Read())// populate buffer with values from db { int value = dr.GetValues(buffer); for (int i = 0; i < buffer.Length; i++) { sb.Append(buffer[i] + ","); } sb.Remove(buffer.Length - 1, 1); } ConsoleKeyInfo cki = new ConsoleKeyInfo(); while (true) // keep console window open { Console.WriteLine("Returned values " + sb.ToString()); cki = Console.ReadKey(true); if (cki.Key == ConsoleKey.X) { break; } } dr.Close(); }