本文整理汇总了C#中System.Data.OleDb.OleDbConnection.Close方法的典型用法代码示例。如果您正苦于以下问题:C# OleDbConnection.Close方法的具体用法?C# OleDbConnection.Close怎么用?C# OleDbConnection.Close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Data.OleDb.OleDbConnection
的用法示例。
在下文中一共展示了OleDbConnection.Close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Select
public DataSet Select(string selstr)
{
DataSet ds = new DataSet();
OleDbConnection conn = new OleDbConnection();
conn.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;" +
"Data Source =" + DBPath;
try
{
conn.Open();
OleDbDataAdapter da = new OleDbDataAdapter(selstr, conn);
da.Fill(ds);
}
catch (Exception)
{
conn.Close();
}
finally
{
conn.Close();
}
return ds;
}
示例2: onClick_login
protected void onClick_login(object sender, EventArgs e)
{
connection = new OleDbConnection(path);
connection.Open();
cmd = new OleDbCommand("SELECT COUNT(*) FROM tblProfiles WHERE user_name = '" + inputUsername.Text + "';", connection);
cmd.ExecuteNonQuery();
int compareUsername = Convert.ToInt32(cmd.ExecuteScalar().ToString());
connection.Close();
if (compareUsername == 1)
{
connection.Open();
cmd = new OleDbCommand("SELECT user_password FROM tblProfiles WHERE user_name = '" + inputUsername.Text + "';", connection);
cmd.ExecuteNonQuery();
string comparePassword = cmd.ExecuteScalar().ToString();
connection.Close();
if (comparePassword == inputPassword.Text)
{
Session["username"] = inputUsername.Text;
Server.Transfer("main.aspx");
}
else
errorPassword.Visible = true;
}
else
errorUsername.Visible = true;
}
示例3: MigrateExcelFile
private void MigrateExcelFile(string fileName,string excel_column_range,string tempTable)
{
string virtualColumns = "null as user_id";
OleDbCommand command = default(OleDbCommand);
OleDbDataReader rdr = default(OleDbDataReader);
OleDbConnection conn = default(OleDbConnection);
try
{
conn = new OleDbConnection(string.Format(excelConnectionString, fileName));
conn.Open();
if (virtualColumns != "") virtualColumns += ",";
command = conn.CreateCommand();
command.CommandText = string.Format("Select {0} * From [{1}]",virtualColumns, excel_column_range);
command.CommandType = CommandType.Text;
rdr = command.ExecuteReader();
if (rdr.HasRows)
{
SqlBulkCopy sqlBulk = new SqlBulkCopy(dbConnection.ConnectionString);
sqlBulk.DestinationTableName = tempTable;
sqlBulk.WriteToServer(rdr);
rdr.Close();
}
conn.Close();
}
catch (Exception ex)
{
if (conn.State == ConnectionState.Open) conn.Close();
throw ex;
};
}
示例4: Getexcelds
/// <summary>
/// ���뵽dataset
/// </summary>
/// <param name="Path"></param>
/// <param name="sheetname"></param>
/// <returns></returns>
public DataSet Getexcelds(string Path, String sheetname)
{
string strConn = string.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source='" + Path + "';Extended Properties='Excel 8.0;HDR=YES;IMEX=1'");//��һ����Ϊ��
OleDbConnection conn = new OleDbConnection(strConn);
conn.Open();
try
{
string strExcel = "select * from [" + sheetname + "]";
if (sheetname.IndexOf('$') < 0)//if it have not $
{
strExcel = "select * from[" + sheetname + "$]";
}
OleDbDataAdapter da = new OleDbDataAdapter(strExcel, strConn);
DataSet ds = new DataSet();
da.Fill(ds, "��˾Ա��");
conn.Close();
return ds;
}
catch (Exception error)
{
return null;
}
finally
{
conn.Close();
}
}
示例5: button2_Click
private void button2_Click(object sender, EventArgs e)
{
string chaine = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:/Users/dhib/Desktop/Professeur.accdb";
OleDbConnection con = new OleDbConnection(chaine);
OleDbCommand cmd = con.CreateCommand();
cmd.CommandText = "select * from module1";
try
{
con.Open();
OleDbDataReader dr = cmd.ExecuteReader();
dataGridView1.Rows.Clear();
while (dr.Read())
{
dataGridView1.Rows.Add(dr.GetValue(1), dr.GetValue(2), dr.GetValue(3), dr.GetValue(4),dr.GetValue(0));
}
dr.Close();
con.Close();
}
catch (Exception ex) { MessageBox.Show("Erreur : " + ex.Message); con.Close(); }
// dataGridView1.CellClick += new DataGridViewCellEventHandler(dataGridView1_CellClick);
}
示例6: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
if (Session["oturumid"] == null)
Response.Redirect("giris.aspx");
else if (Session["oturumdurum"].ToString() == "0")
Response.Redirect("uyepaneli.aspx");
else if (Request.QueryString["mid"] == null|| Request.QueryString["mid"] == "")
Response.Redirect("adminpaneli.aspx");
else
{
string mid = Request.QueryString["mid"];
OleDbConnection cnn = new OleDbConnection("Provider=Microsoft.Jet.Oledb.4.0; Data Source=" + Server.MapPath("App_Data/database.mdb"));
cnn.Open();
OleDbCommand cmd = new OleDbCommand("select * from mesajlar where mesajid=" + mid, cnn);
OleDbDataReader rdr = cmd.ExecuteReader();
if(rdr.Read()==false)
{
cnn.Close();
Response.Redirect("adminpaneli.aspx");
}
else
{
Label2.Text = rdr[1].ToString();
Label4.Text = rdr[2].ToString();
Label6.Text = rdr[3].ToString();
Label7.Text = rdr[4].ToString();
}
if(cnn.State==System.Data.ConnectionState.Open)
cnn.Close();
}
}
示例7: Excel2003ToDataSet
public DataSet Excel2003ToDataSet(string Path)
{
OleDbConnection conn = null;
try
{
string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + Path + ";" + "Extended Properties=Excel 8.0;";
conn = new OleDbConnection(strConn);
conn.Open();
System.Data.DataTable dtSheet = conn.GetOleDbSchemaTable(System.Data.OleDb.OleDbSchemaGuid.Tables, null);
string tableName = dtSheet.Rows[0][2].ToString();
string strExcel = "";
OleDbDataAdapter myCommand = null;
DataSet ds = null;
strExcel = "select * from [" + tableName + "]";
myCommand = new OleDbDataAdapter(strExcel, strConn);
ds = new DataSet();
myCommand.Fill(ds, tableName);
conn.Close();
conn = null;
return ds;
}
catch (Exception ex)
{
if (conn != null && conn.State == ConnectionState.Open)
conn.Close();
conn = null;
throw;
}
}
示例8: SelectFromXLS
/// <summary>
/// 执行查询
/// </summary>
/// <param name="ServerFileName">xls文件路径</param>
/// <param name="SelectSQL">查询SQL语句</param>
/// <returns>DataSet</returns>
public static System.Data.DataSet SelectFromXLS(string ServerFileName, string SelectSQL)
{
string connStr = "Provider = Microsoft.Jet.OLEDB.4.0 ; Data Source = '" + ServerFileName + "';Extended Properties=Excel 8.0";
OleDbConnection conn = new OleDbConnection(connStr);
OleDbDataAdapter da = null;
System.Data.DataSet ds = new System.Data.DataSet();
try
{
conn.Open();
da = new OleDbDataAdapter(SelectSQL, conn);
da.Fill(ds, "SelectResult");
}
catch (Exception e)
{
conn.Close();
throw e;
}
finally
{
conn.Close();
}
return ds;
}
示例9: button2_Click
private void button2_Click(object sender, EventArgs e)
{
string chaine = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:/Users/dhib/Desktop/Professeur.accdb";
OleDbConnection con = new OleDbConnection(chaine);
OleDbCommand cmd = con.CreateCommand();
cmd.CommandText = "Insert into enseignant(login,mdp,nom,prenom,grade) values ('" + txt_insc_login.Text + "','" + txt_insc_password.Text + "','" + txt_insc_family.Text + "','" + txt_insc_name.Text + "','" + txt_insc_grade.Text + "')";
try
{
con.Open();
cmd.ExecuteNonQuery();
MessageBox.Show("Ajout Réussi");
txt_insc_login.Text = "";
txt_insc_password.Text = "";
txt_insc_family.Text = "";
txt_insc_name.Text = "";
txt_insc_grade.Text = "";
con.Close();
new Form1().Show();
this.Hide();
}catch(Exception ex)
{ MessageBox.Show("Erreur" + ex.Message);
con.Close();
}
}
示例10: Main
//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();
}
示例11: button2_Click
private void button2_Click(object sender, EventArgs e)
{
date.CustomFormat = "dd/MM/yyyy";
string chaine = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:/Users/dhib/Desktop/Professeur.accdb";
OleDbConnection con = new OleDbConnection(chaine);
OleDbCommand cmd = con.CreateCommand();
cmd.CommandText = "Insert into module1(nom_module,coef,anne,semestre,login_enseignant) values ('" + txt_nv_module.Text + "','" + Convert.ToInt32(txt_coef.Text) + "','" + date.Text + "'," + Convert.ToInt32(txt_semestre.Text) + ",'" + login + "')";
try
{
con.Open();
cmd.ExecuteNonQuery();
MessageBox.Show("Ajout Module Réussi");
txt_nv_module.Text = "";
txt_coef.Text = "";
txt_semestre.Text = "";
con.Close();
new acceuil(login).Show();
this.Hide();
}
catch (Exception ex)
{
MessageBox.Show("Erreur" + ex.Message);
con.Close();
}
}
示例12: ExcelSqlConnection
private static int ExcelMaxRow = 999999999; //Convert.ToInt32(ConfigurationSettings.AppSettings["ExcelMaxRow"]);
#endregion Fields
#region Methods
/// <summary>
/// ����Excel ��ȡExcel���� ������DataSet���ݼ���
/// </summary>
/// <param name="filepath">Excel������·��</param>
/// <param name="tableName">Excel������</param>
/// <returns></returns>
public static System.Data.DataSet ExcelSqlConnection(string filepath, string tableName,string sheetName)
{
string errMsg = string.Empty;
//string strCon = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + filepath + ";Extended Properties='Excel 8.0;HDR=YES;IMEX=1'";
////OleDbConnection ExcelConn = new OleDbConnection(strCon);
//try
//{
// string strCom = string.Format("SELECT * FROM [Sheet1$]");
// DataSet ds = new DataSet();
// ds = DBdb2.RunDataSet(strCom, out errMsg);
// return ds;
//}
//catch
//{
// return null;
//}
string strCon = "Provider=Microsoft.Ace.OleDb.12.0;" + "data source=" + filepath + ";Extended Properties='Excel 12.0; HDR=Yes; IMEX=1'";
OleDbConnection ExcelConn = new OleDbConnection(strCon);
try
{
string strCom = string.Format("SELECT * FROM ["+sheetName+"$]");
ExcelConn.Open();
OleDbDataAdapter myCommand = new OleDbDataAdapter(strCom, ExcelConn);
DataSet ds = new DataSet();
myCommand.Fill(ds, "[" + tableName + "$]");
ExcelConn.Close();
return ds;
}
catch
{
ExcelConn.Close();
return null;
}
}
示例13: FrmMain_Load
private void FrmMain_Load(object sender, EventArgs e)
{
this.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint, true);
string strPath = System.IO.Directory.GetCurrentDirectory() + BGimage;
this.BackgroundImage = Image.FromFile(strPath);
BtnStart.Image = Image.FromFile(System.IO.Directory.GetCurrentDirectory() + "\\images\\btn_start.png");
//从数据库里读出所有可抽奖人员
OleDbConnection odcConnection = new OleDbConnection(strConn);
odcConnection.Open();
OleDbCommand odCommand = odcConnection.CreateCommand();
odCommand.CommandText = "select count(*) as result from seedlist";
OleDbDataReader odrCount = odCommand.ExecuteReader();
odrCount.Read();
int allcount = Int32.Parse(odrCount[0].ToString());
odrCount.Close();
if (allcount < 9)
{
odcConnection.Close();
MessageBox.Show("可供抽奖的人数不足,无法抽奖");
this.Close();
}
else
{
//读取所有记录到数据
SeedsList.Items.Clear();
odCommand.CommandText = "select id,employee_dept,employee_name,employee_no from Seedlist where award_flag = '0' order by id asc";
OleDbDataReader odrReader = odCommand.ExecuteReader();
while (odrReader.Read())
{
SeedsList.Items.Add(odrReader[0].ToString() + ";" + odrReader[1].ToString() + ";" + odrReader[2].ToString() + ";" + odrReader[3].ToString());
}
odrReader.Close();
odcConnection.Close();
}
}
示例14: ExecuteReader
public DataSet ExecuteReader(string q)
{
q = CleanQuery(q);
Logger.CreateLog("ExecuteReaderQuery", q, null, EnumLogLevel.INFO);
DataSet dataset = null;
OleDbConnection oConn = new OleDbConnection(GetConnexionString());
oConn.Open();
try
{
OleDbCommand oCmd = new OleDbCommand(q, oConn);
OleDbDataReader reader = oCmd.ExecuteReader();
dataset = this.ConvertDataReaderToDataSet(reader);
}
catch (Exception ex)
{
oConn.Close();
ex.HelpLink = q;
throw ex;
}
oConn.Close();
return dataset;
}
示例15: Button2_Click
protected void Button2_Click(object sender, EventArgs e)
{
string s_add, r_add, message, heading,muid;
s_add = Session["us_name"].ToString();
r_add = TextBox1.Text;
heading = TextBox3.Text;
message = TextBox2.Text;
rec_mail te = new rec_mail();
conn = new OleDbConnection("Provider=MSDAORA;Data Source=orcl;Persist Security Info=True;Password=db_mail;User ID=db_mail");
conn.Open();
cmd = new OleDbCommand("insert into messages values(m_id.nextval,'" + heading + "','" + message + "'," + file_name + "',sysdate,sysdate,'Draft')", conn);
dr = cmd.ExecuteReader();
cmd = new OleDbCommand("insert into mail_exchange values('" + s_add + "',m_id.currval,sysdate,sysdate,'" + r_add + "')", conn);
dr = cmd.ExecuteReader();
cmd = new OleDbCommand("insert into draft values(m_id.currval)", conn);
dr = cmd.ExecuteReader();
dr.Close();
cmd = new OleDbCommand("select m_id.currval from dual", conn);
dr = cmd.ExecuteReader();
dr.Read();
muid = dr[0].ToString();
dr.Close();
conn.Close();
Label1.Text = "Message Saved. Your message id is " + muid;
Label1.Visible = true;
dr.Close();
conn.Close();
}