本文整理汇总了C#中SqlCeConnection.Close方法的典型用法代码示例。如果您正苦于以下问题:C# SqlCeConnection.Close方法的具体用法?C# SqlCeConnection.Close怎么用?C# SqlCeConnection.Close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SqlCeConnection
的用法示例。
在下文中一共展示了SqlCeConnection.Close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateDB
/// <summary>
/// Create the initial database
/// </summary>
private void CreateDB()
{
var connection = new SqlCeConnection(this.path);
try
{
var eng = new SqlCeEngine(this.path);
var cleanup = new System.Threading.Tasks.Task(eng.Dispose);
eng.CreateDatabase();
cleanup.Start();
}
catch (Exception e)
{
EventLogging.WriteError(e);
}
connection.Open();
var usersDB =
new SqlCeCommand(
"CREATE TABLE Users_DB("
+ "UserID int IDENTITY (100,1) NOT NULL UNIQUE, "
+ "UserName nvarchar(128) NOT NULL UNIQUE, "
+ "PassHash nvarchar(128) NOT NULL, "
+ "Friends varbinary(5000), "
+ "PRIMARY KEY (UserID));",
connection);
usersDB.ExecuteNonQuery();
usersDB.Dispose();
connection.Dispose();
connection.Close();
}
示例2: button1_Click
/// <summary>
/// Загрузка данных о игроках и проверка пароля, чтобы можно было
/// загрузить данные о нем.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button1_Click(object sender, EventArgs e)
{
var con = new SqlCeConnection("DataSource=|DataDirectory|\\Database.sdf");
var sqlCommand = new SqlCeCommand("select * from users", con);
con.Open();
var set = sqlCommand.ExecuteResultSet(ResultSetOptions.None);
while (set.Read()) {
var o = set["UserId"];
var o1 = set["Login"];
var o2 = set["Password"];
if (o1.ToString() == textBox1.Text
&& o2.ToString() == textBox2.Text) {
con.Close();
ok = true;
form1.User = new Users {
Login = o1.ToString(),
Password = o2.ToString()
};
Close();
return;
}
}
con.Close();
label3.Text = "Пароль или имя не верны";
}
示例3: createCity
///////////////////
//VILLE
public bool createCity(string name)
{
//Connexion a la bdd
SqlCeConnection ConnectionBdd = new SqlCeConnection(ConnectionString);
try
{
//Ouverture de la connexion
ConnectionBdd.Open();
string query = "INSERT INTO [VILLE] (VILLE_NOM) "
+ "VALUES (" +
"'" + name +
"')";
Console.WriteLine(query);
SqlCeCommand mySqlCommand = new SqlCeCommand(query, ConnectionBdd);
mySqlCommand.ExecuteReader();
Console.WriteLine("--> Nouvelle ville créée : " + name);
ConnectionBdd.Close();
return true;
}
catch (Exception e)
{
Console.WriteLine(e.Message);
ConnectionBdd.Close();
return false;
}
}
示例4: Login_Click
protected void Login_Click(object sender, EventArgs e)
{
SqlCeConnection conn = new SqlCeConnection(connString); // SqlConnection
conn.Open();
//podlozno SQL injection napadu
//SqlCeCommand command = new SqlCeCommand("SELECT * FROM student WHERE ime = '" +
// txtKorisnickoIme.Text + "' AND lozinka = '" +
// txtLozinka.Text + "'", conn);
SqlCeCommand command = new SqlCeCommand("SELECT * FROM student WHERE ime = @ime AND lozinka = @lozinka", conn);
command.Parameters.AddWithValue("ime", txtKorisnickoIme.Text);
command.Parameters.AddWithValue("lozinka", txtLozinka.Text);
SqlCeDataReader dr = command.ExecuteReader();
if (dr.Read())
{
Session["korisnickoIme"] = dr["ime"].ToString();
dr.Close();
conn.Close();
Response.Redirect("Zasticena.aspx");
}
dr.Close();
conn.Close();
}
示例5: btnLogin_Click
private void btnLogin_Click(object sender, EventArgs e)
{
string spath = @"Data Source=Application Data\PDADB.sdf";
string strid = this.txtUserID.Text.Trim();
string strpwd = this.txtPwd.Text.Trim();
if (strid == "")
{
MessageBox.Show("�������û����!", "����", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
return;
}
if (strpwd == "")
{
MessageBox.Show("�������û�����!", "����", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
return;
}
string sql = "select usersn,pwd,flag from tuser where userid ='" + strid + "'";
try
{
conn = new SqlCeConnection(spath);
conn.Open();
SqlCeCommand cmd = new SqlCeCommand();
cmd.Connection = conn;
cmd.CommandText = sql;
SqlCeDataReader read = cmd.ExecuteReader();
if (read.Read())
{
string tmpsn = read[0].ToString();
string tmppwd = read[1].ToString();
string tmpflag = read[2].ToString();
conn.Close();
if (tmpflag != "0")
{
MessageBox.Show("����Ч�û�!" , "����", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
return;
}
if (tmppwd != strpwd)
{
MessageBox.Show("�û����벻��ȷ!" , "����", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
return;
}
CurrentUser.USERSN = tmpsn;
frmMain fm = new frmMain();
fm.ShowDialog();
}
else
{
conn.Close();
MessageBox.Show("û�ҵ��û���Ϣ!" , "����", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
return;
}
}
catch (Exception ex)
{
conn.Close();
MessageBox.Show("��½�쳣!"+ ex.Message, "����", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
return;
}
}
示例6: deleteDocCheckProduct
public bool deleteDocCheckProduct(string _DCode)
{
bool result = false;
try
{
Conn = OpenConn();
sb = new StringBuilder();
sb.Append(" delete from DocCheckProducts where DCode ='"+_DCode+"'");
string sqlAdd;
sqlAdd = sb.ToString();
tr = Conn.BeginTransaction();
com = new SqlCeCommand();
com.CommandText = sqlAdd;
com.CommandType = CommandType.Text;
com.Connection = Conn;
com.Transaction = tr;
com.ExecuteNonQuery();
tr.Commit();
sb = new StringBuilder();
sb.Append(" delete from DocCheckProductDetails where DCode ='" + _DCode + "'");
string sqldelete;
sqldelete = sb.ToString();
tr = Conn.BeginTransaction();
com = new SqlCeCommand();
com.CommandText = sqldelete;
com.CommandType = CommandType.Text;
com.Connection = Conn;
com.Transaction = tr;
com.ExecuteNonQuery();
tr.Commit();
result = true;
}
catch (Exception ex)
{
tr.Rollback();
Conn.Close();
result = false;
Console.WriteLine(ex.Message);
}
finally
{
Conn.Close();
}
return result;
}
示例7: Execute
public bool Execute(string query)
{
SqlCeConnection sqlcon = new SqlCeConnection(Database.Connection);
SqlCeCommand sqlcom = new SqlCeCommand(query, sqlcon);
if (sqlcon.State != ConnectionState.Closed)
{
sqlcon.Close();
}
sqlcon.Open();
sqlcom.ExecuteNonQuery();
sqlcon.Close();
return true;
}
示例8: ApplicationState
private ApplicationState()
{
// read the application state from db
SqlCeConnection _dataConn = null;
try
{
_dataConn = new SqlCeConnection("Data Source=FlightPlannerDB.sdf;Persist Security Info=False;");
_dataConn.Open();
SqlCeCommand selectCmd = new SqlCeCommand();
selectCmd.Connection = _dataConn;
StringBuilder selectQuery = new StringBuilder();
selectQuery.Append("SELECT cruiseSpeed,cruiseFuelFlow,minFuel,speed,unit,utcOffset,locationFormat,deckHoldFuel,registeredClientName FROM ApplicationState");
selectCmd.CommandText = selectQuery.ToString();
SqlCeResultSet results = selectCmd.ExecuteResultSet(ResultSetOptions.Scrollable);
if (results.HasRows)
{
results.ReadFirst();
cruiseSpeed = results.GetInt64(0);
cruiseFuelFlow = results.GetInt64(1);
minFuel = results.GetInt64(2);
speed = results.GetSqlString(3).ToString();
unit = results.GetSqlString(4).ToString();
utcOffset = results.GetSqlString(5).ToString();
locationFormat = results.GetSqlString(6).ToString();
deckHoldFuel = results.IsDBNull(7) ? 0 : results.GetInt64(7);
registeredClientName = results.IsDBNull(8) ? string.Empty : results.GetString(8);
}
}
finally
{
_dataConn.Close();
}
}
示例9: CreateUser
public static User CreateUser(string username, string password)
{
SqlCeConnection con = new SqlCeConnection(CONNECTION_STRING);
try
{
con.Open();
SqlCeCommand comm = new SqlCeCommand("INSERT INTO users (username, password, salt, dateCreated) VALUES (@username, @password, @salt, @createdDate)", con);
comm.Parameters.Add(new SqlCeParameter("@username", username));
comm.Parameters.Add(new SqlCeParameter("@password", password));
comm.Parameters.Add(new SqlCeParameter("@salt", String.Empty));
comm.Parameters.Add(new SqlCeParameter("@createdDate", DateTime.UtcNow));
int numberOfRows = comm.ExecuteNonQuery();
if (numberOfRows > 0)
{
return GetUser(username);
}
}
catch (Exception ex)
{
Debug.Print("CreateUser Exception: " + ex);
}
finally
{
if (con != null && con.State == ConnectionState.Open)
{
con.Close();
}
}
return null;
}
示例10: postavi_labele
private void postavi_labele()
{
//kreiraj novu praznu konekciju
SqlCeConnection conn = new SqlCeConnection();
//dohvati tekst za povezivanje na bazu iz web.config i postavi g ana konekciju
string connStr = WebConfigurationManager.ConnectionStrings["studenti"].ConnectionString;
conn.ConnectionString = connStr;
//kreiraj novu naredbu i postavi SQL kao i konekciju
SqlCeCommand cmd = new SqlCeCommand();
cmd.Connection = conn;
cmd.CommandText = "SELECT COUNT(*) FROM student";
cmd.CommandType = System.Data.CommandType.Text; //tip je SQL naredba (a ne tablica ili stor.proc)
//otvori komunikaciju sa bazom
conn.Open();
int brojStud = (int)cmd.ExecuteScalar(); //izvrši vrati jednu vrijednost
Label1.Text = "U bazi imamo " + brojStud.ToString() + " studenata!";
cmd.CommandText = "SELECT * FROM student";
//sada ih vrati kao datareader
SqlCeDataReader dr = cmd.ExecuteReader();
Label2.Text = "ID - Ime - Prezime" + "<br>";
// na sql Expressu ima i dr.HasRows da vidimo je li prazan if(dr.HasRows))
while (dr.Read())
{
//čitaj red po red dok ne dođeš do kraja
Label2.Text += dr["stud_id"].ToString() + " - " + dr["ime"] + " - " + dr["prezime"] + " - " + dr["faks"] + "<br>";
}
conn.Close();
}
示例11: buttonImage1_Click
private void buttonImage1_Click(object sender, EventArgs e)
{
/*
* Verificar se existe coluna e inserir caso n exista
* garantir compatibilidade com bancos velhos
*/
//CONN
SqlCeConnection conn =
new SqlCeConnection("Data Source = " + Library.appDir + "\\db\\citeluz.sdf; [email protected]$X-PRO;");
//coluna user
conn.Open();
SqlCeCommand command = conn.CreateCommand();
command.CommandText = "ALTER TABLE trafo ADD [user] NVARCHAR(15) DEFAULT 'TESTE';";
try
{
command.ExecuteNonQuery();
MessageBox.Show("Tabela trafo atualizada com sucesso");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
conn.Close();
}
}
示例12: ctlrptActiveCall
public ctlrptActiveCall()
{
try
{
InitializeComponent();
ConnectionString = VMuktiAPI.VMuktiInfo.MainConnectionString;
if (System.IO.File.Exists(AppDomain.CurrentDomain.BaseDirectory.ToString() + "rptActiveCall.sdf"))
{
System.IO.File.Delete(AppDomain.CurrentDomain.BaseDirectory.ToString() + "rptActiveCall.sdf");
}
SqlCeEngine clientEngine = new SqlCeEngine(ClientConnectionString);
clientEngine.CreateDatabase();
LocalSQLConn = new SqlCeConnection();
LocalSQLConn.ConnectionString = ClientConnectionString;
LocalSQLConn.Open();
fncActiveCallTable();
LocalSQLConn.Close();
objRefreshReport = new delRefreshReport(fncRefreshReport);
NetPeerClient npcActiveCall = new NetPeerClient();
((NetP2PBootStrapActiveCallReportDelegates)objActiveCall).EntsvcJoinCall += new NetP2PBootStrapActiveCallReportDelegates.DelsvcJoinCall(ctlrptActiveCall_EntsvcJoinCall);
((NetP2PBootStrapActiveCallReportDelegates)objActiveCall).EntsvcGetCallInfo += new NetP2PBootStrapActiveCallReportDelegates.DelsvcGetCallInfo(ctlrptActiveCall_EntsvcGetCallInfo);
((NetP2PBootStrapActiveCallReportDelegates)objActiveCall).EntsvcActiveCalls += new NetP2PBootStrapActiveCallReportDelegates.DelsvcActiveCalls(ctlrptActiveCall_EntsvcActiveCalls);
((NetP2PBootStrapActiveCallReportDelegates)objActiveCall).EntsvcSetDuration += new NetP2PBootStrapActiveCallReportDelegates.DelsvcSetDuration(ctlrptActiveCall_EntsvcSetDuration);
((NetP2PBootStrapActiveCallReportDelegates)objActiveCall).EntsvcUnJoinCall += new NetP2PBootStrapActiveCallReportDelegates.DelsvcUnJoinCall(ctlrptActiveCall_EntsvcUnJoinCall);
channelNetTcpActiveCall = (INetP2PBootStrapReportChannel)npcActiveCall.OpenClient<INetP2PBootStrapReportChannel>("net.tcp://" + VMuktiAPI.VMuktiInfo.BootStrapIPs[0] + ":6000/NetP2PBootStrapActiveCallReport", "ActiveCallMesh", ref objActiveCall);
channelNetTcpActiveCall.svcJoinCall(VMuktiAPI.VMuktiInfo.CurrentPeer.DisplayName);
}
catch (Exception ex)
{
VMuktiAPI.VMuktiHelper.ExceptionHandler(ex, "ctlrptActiveCall", "ctlrptActiveCall.xaml.cs");
}
}
示例13: registriraj
public bool registriraj(string korisnickoIme, string lozinka, string address, string email)
{
SqlCeConnection conn = new SqlCeConnection(connString);
try
{
Random r = new Random(System.DateTime.Now.Millisecond);
string salt = r.Next().ToString();
string hashiranaLoznika = Util.SHA256(lozinka);
string hashiranaSlanaLoznika = Util.SHA256(salt + hashiranaLoznika);
conn.Open();
SqlCeCommand command = new SqlCeCommand
("INSERT INTO Kori(username,password,salt,address,email) VALUES (@username,@password,@salt,@address,@email)",conn);
command.Parameters.AddWithValue("username", korisnickoIme);
command.Parameters.AddWithValue("password", hashiranaSlanaLoznika);
command.Parameters.AddWithValue("salt", salt);
command.Parameters.AddWithValue("address", address);
command.Parameters.AddWithValue("email", email);
command.ExecuteNonQuery();
conn.Close();
return true;
}
catch (Exception ex)
{
return false;
}
}
示例14: Alterar
public bool Alterar(EMovimentacaoConta movementacaoConta)
{
SqlCeConnection cnn = new SqlCeConnection();
cnn.ConnectionString = Conexao.Caminho;
SqlCeCommand cmd = new SqlCeCommand();
cmd.Connection = cnn;
#region alteracao do associado
cmd.CommandText = @"UPDATE MovimentacaoConta SET
dataHoraMovimentacao = @dataHoraMovimentacao,
valortotal = @valortotal,
Id_Associado = @Id_Associado,
Id_Movimentacao = @Id_Movimentacao
ListaItens = @ListaItens
WHERE Id_Movimentacao = @Id ";
cmd.Parameters.Add("@Nome", movementacaoConta.DataHoraMovimentacao);
cmd.Parameters.Add("@valorTotal", movementacaoConta.Valortotal);
cmd.Parameters.Add("@IdMovimentacao", movementacaoConta.IdAssociado);
cmd.Parameters.Add("@IdMovimentacao", movementacaoConta.IdMovimentacao);
cmd.Parameters.Add("@Listaitens", movementacaoConta.ListaItens);
//Executa o comando setado - UPDATE
cnn.Open();
cmd.ExecuteNonQuery();
#endregion alteracao do associado
//Fecha a conexão
cnn.Close();
return true;
}
示例15: btnDelete_Click
private void btnDelete_Click(object sender, EventArgs e)
{
btnSave.Enabled = false;
grbDeviceIP.Enabled = false;
dataSourcePath = "Data Source = " + Application.StartupPath + @"\DeviceData.sdf";
SqlCeConnection sqlConnection1 = new SqlCeConnection();
sqlConnection1.ConnectionString = dataSourcePath;
SqlCeCommand cmd = new SqlCeCommand();
cmd.CommandType = System.Data.CommandType.Text;
cmd.Connection = sqlConnection1;
sqlConnection1.Open();
try
{
cmd.CommandText = "DELETE FROM DeviceData WHERE DEVICE_IP='" + Global.selMechIp + "'";
cmd.ExecuteNonQuery();
cmd.CommandText = "DELETE FROM DeviceURL WHERE DEV_IP='" + Global.selMechIp + "'";
cmd.ExecuteNonQuery();
}
catch { }
sqlConnection1.Dispose();
sqlConnection1.Close();
fnGetIpsFronTable();
btnDelete.Enabled = false;
btnEdit.Enabled = false;
txtDevIp.Text = "";
txtDevNo.Text = "";
txtDevPort.Text = "";
Application.DoEvents();
}