本文整理汇总了C#中SQL.Open方法的典型用法代码示例。如果您正苦于以下问题:C# SQL.Open方法的具体用法?C# SQL.Open怎么用?C# SQL.Open使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SQL
的用法示例。
在下文中一共展示了SQL.Open方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Create
public Exception Create(NumeroControl numControl)
{
//using (SqlConnection conn = sql.GetConnection())
using (SqlConnection conn = new SQL().GetLocalConnection())
{
SqlCommand cmd = new SqlCommand(@"UPDATE NumeroControl SET NumControl = @NumControl WHERE AnoCorriente = @Year;", conn);
cmd.Parameters.AddWithValue("Year", numControl.Year);
cmd.Parameters.AddWithValue("NumControl", numControl.NumControl);
conn.Open();
using (SqlTransaction transaction = conn.BeginTransaction())
{
cmd.Transaction = transaction;
try
{
cmd.ExecuteNonQuery();
transaction.Commit();
return null;
}
catch (Exception ex)
{
transaction.Rollback();
return ex;
}
}
}
}
示例2: buscarBtn_Click
protected void buscarBtn_Click(object sender, EventArgs e)
{
lookupDiv.Visible = true;
avisosGv.Visible = false;
LinkedList<Averia> averias = AveriasServicio.GetAveriasByMunicipio(municipioDDL.SelectedValue);
averiasLbl.Text = string.Format("Total de Averias Cometidas por Municipio: {0}", averias.Count);
if (averias.Count > 0)
{
#region Fill gv
avisosGv.Visible = true;
using (SqlConnection conn = new SQL().GetLocalConnection())
{
using (SqlCommand cmd = new SqlCommand(@"SELECT * FROM Averias WHERE Municipio = @Municipio", conn))
{
cmd.Parameters.AddWithValue("Municipio", municipioDDL.SelectedValue);
conn.Open();
cmd.ExecuteNonQuery();
DataTable dt = new DataTable();
using (SqlDataAdapter adapter = new SqlDataAdapter(cmd))
{
adapter.Fill(dt);
}
avisosGv.DataSourceID = string.Empty;
avisosGv.DataSource = dt;
avisosGv.DataBind();
}
}
#endregion
}
}
示例3: GetNumeroControl
public NumeroControl GetNumeroControl(int year)
{
NumeroControl numeroControl = null;
//SQL sql = new SQL();
//using (SqlConnection conn = sql.GetConnection())
using (SqlConnection conn = new SQL().GetLocalConnection())
{
SqlCommand cmd = new SqlCommand(@"SELECT AnoCorriente, NumControl FROM NumeroControl
WHERE AnoCorriente = @Year;", conn);
cmd.Parameters.AddWithValue("Year", year);
conn.Open();
cmd.ExecuteNonQuery();
SqlDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
int col = 0;
numeroControl = new NumeroControl()
{
Year = Convert.ToInt32(reader[col]),
NumControl = Convert.ToInt32(reader[col + 1]),
NumControlText = reader[col].ToString() + reader[col + 1].ToString()
};
}
}
return numeroControl;
}
示例4: GetMailMsgs
public LinkedList<Mail> GetMailMsgs()
{
//using (SqlConnection conn = sql.GetConnection())
using (SqlConnection conn = new SQL().GetLocalConnection())
{
#region Sql command
SqlCommand cmd = new SqlCommand(@"SELECT TituloMensaje, Mensaje
FROM MensajesCorreo ORDER BY MensajeID;", conn);
#endregion
conn.Open();
cmd.ExecuteNonQuery();
SqlDataReader reader = cmd.ExecuteReader();
LinkedList<Mail> mails = new LinkedList<Mail>();
while (reader.Read())
{
int col = 0;
mails.AddLast(new Mail()
{
Subject = reader.GetString(col++),
Body = reader.GetString(col++)
});
}
return mails;
}
}
示例5: itemSelected
protected void itemSelected(object sender, EventArgs e)
{
string connectionString = null;
SqlConnection conn;
SqlCommand command; string sql = null;
SqlDataReader dataReader;
//connectionString = "Data Source=(local)\\SQLEXPRESS;Initial Catalog=DEDT;User ID=excdem;Password=excdem";
if (Inspector.SelectedIndex > 0 || Inspector.Items.Count < 2)
{
sql = string.Format(@"SELECT NumeroControl AS CN,
(NombreEmpresa) AS NE, TipoAviso AS Ext, (RepresentanteAutorizado) AS RA, (CONVERT(VARCHAR(10), FechaComienzo, 101)) AS FC,
(CONVERT(VARCHAR(10), FechaExpiracion, 101)) AS FE, (TelOficina) AS Tel,
(CorreoElectronico) AS CE FROM Inspecciones where NombreInspector = '{0}'", Inspector.SelectedValue);
}
else
{
sql = @"SELECT NumeroControl AS CN,
(NombreEmpresa) AS NE, TipoAviso AS Ext, (RepresentanteAutorizado) AS RA, (CONVERT(VARCHAR(10), FechaComienzo, 101)) AS FC,
(CONVERT(VARCHAR(10), FechaExpiracion, 101)) AS FE, (TelOficina) AS Tel,
(CorreoElectronico) AS CE FROM Inspecciones";
}
//conn = new SqlConnection(connectionString);
conn = new SQL().GetLocalConnection();
try
{
conn.Open();
command = new SqlCommand(sql, conn);
DataTable dt = new DataTable();
using (SqlDataAdapter adapter = new SqlDataAdapter(command))
{
adapter.Fill(dt);
}
//dataReader = command.ExecuteReader();
//while (dataReader.Read())
//{
// // MessageBox.Show(dataReader.GetValue(0) + " - " + dataReader.GetValue(1) + " - " + dataReader.GetValue(2));
// //ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('" + dataReader.GetString(0) + " - " + dataReader.GetString(1), true);
// //Console.WriteLine("{0} {1} {2}", dataReader.GetString(0), dataReader.GetString(1));
//}
inspeccionesPendGV.DataSourceID = string.Empty;
inspeccionesPendGV.DataSource = dt;
inspeccionesPendGV.DataBind();
//dataReader.Close();
command.Dispose(); conn.Close();
}
catch (Exception ex)
{
// MessageBox.Show("Can not open connection ! ");
ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('No se puede hacer connección con la Base de Datos.' " + ex, true);
}
}
示例6: GridView1_RowDataBound
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
var hasUpdated = Session["hasUpdated"] == null ? false : (bool)Session["hasUpdated"];
if (hasUpdated)
{
int affectedRow = (int)Session["UpdatedRow"];
if (affectedRow == e.Row.RowIndex && e.Row.Cells.Count >= 2)
{
using (SqlConnection conn = new SQL().GetLocalConnection())
{
conn.Open();
#region Sql command
SqlCommand cmd = new SqlCommand(@"UPDATE Usuarios SET PlacaInspector = @PlacaInspector, NombreUsuario = @NombreInspector,
CorreoElectronico = @CorreoElectronico
WHERE NombreUsuario = @OldName;", conn);
#endregion
#region Command Parameteres
//int affectedRow = (int)Session["UpdatedRow"];
cmd.Parameters.AddWithValue("PlacaInspector", e.Row.Cells[0].Text);
cmd.Parameters.AddWithValue("NombreInspector", e.Row.Cells[1].Text.Replace("Ñ", "ñ").ToUpper());
cmd.Parameters.AddWithValue("CorreoElectronico", e.Row.Cells[2].Text);
cmd.Parameters.AddWithValue("OldName", (string)Session["InspectorNombre"]);
#endregion
using (SqlTransaction transaction = conn.BeginTransaction())
{
cmd.Transaction = transaction;
try
{
cmd.ExecuteNonQuery();
transaction.Commit();
Session["hasUpdated"] = false;
}
catch (Exception ex)
{
transaction.Rollback();
#region Log errors
String errorLog = "Date: " + DateTime.Now.ToLongDateString() + "\r\n Nom.Inspector:" + GridView1.Rows[affectedRow].Cells[1].Text
+ "\r\n Message: " + ex.Message + "\r\n Source: "
+ ex.Source + "\r\n Stacktrace: " + ex.StackTrace + "\r\n TargetSite: " + ex.TargetSite.ToString() + "\r\n\r\n";
//File.WriteAllText("SolicitudInicLog.txt", errorLog);
#endregion
}
}
}
}
}
}
示例7: GetSegundasExtensionesActivas
public static LinkedList<SolicitudAviso> GetSegundasExtensionesActivas()
{
LinkedList<SolicitudAviso> solicitudes = new LinkedList<SolicitudAviso>();
using (SqlConnection conn = new SQL().GetLocalConnection())
{
SqlCommand cmd = new SqlCommand(@"SELECT * FROM Extension2 WHERE EstatusID <> @Inactiva AND EstatusID <> @Eliminada AND EstatusID <> @DENEGADA
AND EstatusID <> @PendRevisar", conn);
cmd.Parameters.AddWithValue("Inactiva", string.Format("S{0}", ((int)SolicitudAviso.Estatus.Inactiva).ToString()));
cmd.Parameters.AddWithValue("Eliminada", string.Format("S{0}", ((int)SolicitudAviso.Estatus.Eliminada).ToString()));
cmd.Parameters.AddWithValue("DENEGADA", string.Format("S{0}", ((int)SolicitudAviso.Estatus.Denegada).ToString()));
cmd.Parameters.AddWithValue("PendRevisar", string.Format("S{0}", ((int)SolicitudAviso.Estatus.PendienteRevisarCoordinador).ToString()));
conn.Open();
cmd.ExecuteNonQuery();
solicitudes = BuildSolicitudes(cmd);
}
return solicitudes;
}
示例8: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
User user = Session["UserObj"] == null ? new User() : (User)Session["UserObj"];
if (user == null)
{
user = new User();
}
if (!user.Rol.VerRegistrar)
{
if (!Request.QueryString["Email"].Replace("%40", "@").Equals(user.Email))
Response.Redirect("~/Default.aspx");
}
var title = (HtmlGenericControl)Master.FindControl("pageTitleSpan");
title.InnerText = Title;
#region Fill Roles ddl
//LinkedList<Role> roles = new RolesServicio().GetRoles();
foreach (var r in roles)
{
roleDDL.Items.Add(r.Nombre);
}
#endregion
#region Fill company
var companies = new SolicitudesInicialesServicio().GetCompanies();
ddlEmpresas.Items.Add("Seleccionar Entidad");
foreach (var c in companies)
{
ddlEmpresas.Items.Add(c.NombreEmpresa);
}
#endregion
#region Fill pregunta seguridad
using (var conn = new SQL().GetLocalConnection())
{
var cmd = new SqlCommand("SELECT PreguntaSeg FROM PreguntasSeg", conn);
conn.Open();
SqlDataReader reader = cmd.ExecuteReader();
//cmd.ExecuteNonQuery();
//DataTable dt = new DataTable();
//using (SqlDataAdapter adapter = new SqlDataAdapter(cmd))
//{
// adapter.Fill(dt);
//}
PreguntaSeguridad.DataSource = reader;
PreguntaSeguridad.DataBind();
}
#endregion
//lblId.Text = Request.QueryString["ID"].ToString();
if (!IsPostBack)
{
if (user.Rol.ID == (int)Role.TipoRoles.Admin)
{
rolTR.Style.Add("display", "normal");
ddlEmpresas.Items.Add("DTOP");
ddlEmpresas.SelectedValue = "DTOP";
}
if (!string.IsNullOrWhiteSpace(Request.QueryString["Email"]))
{
//Evitar que entren a pagina usando query string sin ser user auth, actual user o teniendo el permiso
if (!Request.QueryString["Email"].Replace("%40", "@").Equals(user.Email)) //Check edit user permission goes here*/)
{
if (user.Rol.ID != (int)Role.TipoRoles.Admin)
Response.Redirect("~/Account/Ingresar.aspx");
}
//Hacer esto despues del page load o quiza hacerle load a los ddl antes
User selectedUser = new SolicitudesInicialesServicio().GetUser(Request.QueryString["Email"].Replace("%40", "@"));
NombreUsuario.Text = selectedUser.Nombre;
//if (ddlEmpresas.Items.FindByValue(selectedUser.EmpresaID) == null)
//{
// ddlEmpresas.Items.Add(selectedUser.EmpresaID);
//.........这里部分代码省略.........
示例9: FillSinFiltroGv
private void FillSinFiltroGv()
{
using (SqlConnection conn = new SQL().GetLocalConnection())
{
using (SqlCommand cmd = new SqlCommand(@"SELECT * FROM Averias ORDER BY Municipio", conn))
{
conn.Open();
cmd.ExecuteNonQuery();
DataTable dt = new DataTable();
using (SqlDataAdapter adapter = new SqlDataAdapter(cmd))
{
adapter.Fill(dt);
}
averiasSinFiltroGv.DataSourceID = string.Empty;
averiasSinFiltroGv.DataSource = dt;
averiasSinFiltroGv.DataBind();
}
}
}
示例10: Create
public Exception Create(Messenger mes)
{
//using (SqlConnection conn = sql.GetConnection())
using (SqlConnection conn = new SQL().GetLocalConnection())
{
#region Sql command
SqlCommand cmd = new SqlCommand(@"INSERT INTO MensajeroLog(ExtensionID, FechaEjecucion, NumerosControlSolicitudesDenegadas,
SolicitudesDenegadas, NumerosControlSolicitudesExpiradas, SolicitudesExpiradas,
NumerosControlSolicitudesAExpirar, SolicitudesAExpirar, NumerosControlSolicitudesOperadoresSinResponder5,
OperadoresSinResponder5, NumerosControlSolicitudesOperadoresSinResponder7, OperadoresSinResponder7)
VALUES(@ExtensionID, @FechaEjecucion, @NumerosControlSolicitudesDenegadas, @SolicitudesDenegadas,
@NumerosControlSolicitudesExpiradas, @SolicitudesExpiradas, @NumerosControlSolicitudesAExpirar,
@SolicitudesAExpirar, @NumerosControlSolicitudesOperadoresSinResponder5, @OperadoresSinResponder5,
@NumerosControlSolicitudesOperadoresSinResponder7, @OperadoresSinResponder7);", conn);
#endregion
#region Command Parameteres
cmd.Parameters.AddWithValue("ExtensionID", mes.ExtensionID);
cmd.Parameters.AddWithValue("FechaEjecucion", mes.FechaEjecucion);
cmd.Parameters.AddWithValue("NumerosControlSolicitudesAExpirar", mes.NumerosControlSolicitudesAExpirar);
cmd.Parameters.AddWithValue("NumerosControlSolicitudesDenegadas", mes.NumerosControlSolicitudesDenegadas);
cmd.Parameters.AddWithValue("NumerosControlSolicitudesExpiradas", mes.NumerosControlSolicitudesExpiradas);
cmd.Parameters.AddWithValue("NumerosControlSolicitudesOperadoresSinResponder5", mes.NumerosControlSolicitudesOperadoresSinResponder5);
cmd.Parameters.AddWithValue("NumerosControlSolicitudesOperadoresSinResponder7", mes.NumerosControlSolicitudesOperadoresSinResponder7);
cmd.Parameters.AddWithValue("OperadoresSinResponder5", mes.OperadoresSinResponder5);
cmd.Parameters.AddWithValue("OperadoresSinResponder7", mes.OperadoresSinResponder7);
cmd.Parameters.AddWithValue("SolicitudesAExpirar", mes.SolicitudesAExpirar);
cmd.Parameters.AddWithValue("SolicitudesDenegadas", mes.SolicitudesDenegadas);
cmd.Parameters.AddWithValue("SolicitudesExpiradas", mes.SolicitudesExpiradas);
#endregion
conn.Open();
using (SqlTransaction transaction = conn.BeginTransaction())
{
cmd.Transaction = transaction;
try
{
cmd.ExecuteNonQuery();
transaction.Commit();
return null;
}
catch (SqlException ex)
{
transaction.Rollback();
//String errorLog = "Date: " + DateTime.Now.ToLongDateString() + "\r\n NumeroControl:" + solicitud.NumeroControl.NumControlText
// + "\r\n Message: " + ex.Message + "\r\n Source: "
// + ex.Source + "\r\n Stacktrace: " + ex.StackTrace + "\r\n TargetSite: " + ex.TargetSite.ToString() + "\r\n\r\n";
//File.WriteAllText("SolicitudInicLog.txt", errorLog);
return ex;
}
}
}
}
示例11: Delete
public Exception Delete(NumeroControl numControl, string tipoAviso)
{
//using (SqlConnection conn = sql.GetConnection())
using (SqlConnection conn = new SQL().GetLocalConnection())
{
#region Sql command
SqlCommand cmd = new SqlCommand(@"DELETE FROM Inspecciones WHERE NumeroControl = @NumeroControl AND TipoAviso = @TipoAviso;", conn);
#endregion
#region Command Parameteres
cmd.Parameters.AddWithValue("NumeroControl", numControl.NumControlText);
cmd.Parameters.AddWithValue("TipoAviso", tipoAviso);
#endregion
conn.Open();
using (SqlTransaction transaction = conn.BeginTransaction())
{
cmd.Transaction = transaction;
try
{
cmd.ExecuteNonQuery();
transaction.Commit();
return null;
//return cmd.Transaction;
}
catch (SqlException ex)
{
transaction.Rollback();
//String errorLog = "Date: " + DateTime.Now.ToLongDateString() + "\r\n NumeroControl:" + inspeccion.NumeroControl.NumControlText
// + "\r\n Message: " + ex.Message + "\r\n Source: "
// + ex.Source + "\r\n Stacktrace: " + ex.StackTrace + "\r\n TargetSite: " + ex.TargetSite.ToString() + "\r\n\r\n";
//File.WriteAllText(Microsoft.SqlServer.Server.MapPath"SolicitudInicLog.txt", errorLog);
return ex;
//return cmd.Transaction;
}
}
}
}
示例12: GetRespuestaAviso
public Respuesta GetRespuestaAviso(int id, NumeroControl numControl)
{
Respuesta respuesta = new Respuesta();
//using (SqlConnection conn = sql.GetConnection())
using (SqlConnection conn = new SQL().GetLocalConnection())
{
SqlCommand cmd = new SqlCommand(@"SELECT * FROM Respuestas WHERE Operador = @Operador AND NumeroControl = @NumeroControl", conn);
cmd.Parameters.AddWithValue("Operador", id.ToString());
cmd.Parameters.AddWithValue("NumeroControl", numControl.NumControlText);
conn.Open();
cmd.ExecuteNonQuery();
respuesta = BuildRespuesta(cmd);
}
return respuesta;
}
示例13: GetRespuestasAvisosResumen
public LinkedList<Respuesta> GetRespuestasAvisosResumen(NumeroControl numControl , LinkedList<Operador> operadores)
{
LinkedList<Respuesta> respuestas = new LinkedList<Respuesta>();
//using (SqlConnection conn = sql.GetConnection())
using (SqlConnection conn = new SQL().GetLocalConnection())
{
SqlCommand cmd = new SqlCommand(@"SELECT Operador, DescripcionTrabajo FROM Respuestas WHERE NumeroControl = @NumeroControl", conn);
cmd.Parameters.AddWithValue("NumeroControl", numControl.NumControlText);
conn.Open();
cmd.ExecuteNonQuery();
respuestas = BuildRespuestasResumen(cmd, operadores);
}
return respuestas;
}
示例14: GetRespuestas
public LinkedList<Respuesta> GetRespuestas(Operador operador)
{
LinkedList<Respuesta> respuestas = new LinkedList<Respuesta>();
//using (SqlConnection conn = sql.GetConnection())
using (SqlConnection conn = new SQL().GetLocalConnection())
{
SqlCommand cmd = new SqlCommand(@"SELECT NumeroControl, Operador,
BoUrb + ' ' + SectorCalle + ' ' + Carretera, DescripcionTrabajo, PersonaContacto FROM Respuestas
WHERE Operador = @Operado ORDER BY NumeroControl", conn);
cmd.Parameters.AddWithValue("Operado", operador.OperadorId);
conn.Open();
cmd.ExecuteNonQuery();
respuestas = BuildRespuestasOperador(cmd);
}
return respuestas;
}
示例15: DeleteByNumeroControl
public static Exception DeleteByNumeroControl(string numControl)
{
using (SqlConnection conn = new SQL().GetLocalConnection())
{
conn.Open();
SqlCommand cmd = new SqlCommand(@"DELETE FROM Respuestas WHERE NumeroControl = @NumeroControl;", conn);
#region SQL params
cmd.Parameters.AddWithValue("NumeroControl", numControl);
#endregion
using (SqlTransaction transaction = conn.BeginTransaction())
{
cmd.Transaction = transaction;
try
{
cmd.ExecuteNonQuery();
transaction.Commit();
return null;
}
catch (SqlException ex)
{
transaction.Rollback();
#region Log errores
String errorLog = "Date: " + DateTime.Now.ToLongDateString() + "\r\n NumeroControl:" + numControl
+ "\r\n Message: " + ex.Message + "\r\n Source: "
+ ex.Source + "\r\n Stacktrace: " + ex.StackTrace + "\r\n TargetSite: " + ex.TargetSite.ToString() + "\r\n\r\n";
//File.WriteAllText("AveriasLog.txt", errorLog);
return ex;
#endregion
}
}
}
}