当前位置: 首页>>代码示例>>C#>>正文


C# SqlConnection.Open方法代码示例

本文整理汇总了C#中System.Data.SqlClient.SqlConnection.Open方法的典型用法代码示例。如果您正苦于以下问题:C# SqlConnection.Open方法的具体用法?C# SqlConnection.Open怎么用?C# SqlConnection.Open使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Data.SqlClient.SqlConnection的用法示例。


在下文中一共展示了SqlConnection.Open方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: LoginButton_Click

        protected void LoginButton_Click(object sender, EventArgs e)
        {
            PasswordErrorLB.Text = "";
            UserNameErrorLB.Text = "";
            SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["RegistrationConnectionString"].ConnectionString);
            conn.Open();
            string checkUser = "SELECT count(*) FROM UserDataTable WHERE Username ='" + UserNameTB.Text + "'";
            SqlCommand com = new SqlCommand(checkUser, conn);
            int numUsers = Convert.ToInt32(com.ExecuteScalar().ToString());
            conn.Close();
            if (numUsers == 1)
            {
                conn.Open();
                string checkPassword = "SELECT Password FROM UserDataTable WHERE Username ='" + UserNameTB.Text + "'";
                SqlCommand com2 = new SqlCommand(checkPassword, conn);
                string password = com2.ExecuteScalar().ToString().Replace(" ", "");
                conn.Close();

                if(password == PasswordTB.Text)
                {
                    Session["New"] = UserNameTB.Text;
                    Response.Redirect("MainMenuPage.aspx");
                }
                else
                {
                    PasswordErrorLB.Text = "You Must Enter a Correct Password";
                }
            }
            else
            {
                UserNameErrorLB.Text = "You Must Enter a Correct Username";
            }
        }
开发者ID:sdunn94,项目名称:SoftwareDesignFinal,代码行数:33,代码来源:LoginPage.aspx.cs

示例2: ConfirmQrCode

    public static string ConfirmQrCode(int qrCode, string newUserOpenId)
    {
        string originalUserOpenId = "";
        SqlConnection conn = new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["constr"].Trim());
        SqlCommand cmd = new SqlCommand(" select qr_invite_list_owner from qr_invite_list where qr_invite_list_id = " + qrCode.ToString(), conn);
        conn.Open();
        SqlDataReader drd = cmd.ExecuteReader();
        if (drd.Read())
        {
            originalUserOpenId = drd.GetString(0);
        }
        drd.Close();
        conn.Close();
        cmd.CommandText = " insert into qr_invite_list_detail ( qr_invite_list_detail_id , qr_invite_list_detail_openid ) "
            + " values ('" + qrCode.ToString() + "' , '" + newUserOpenId.Replace("'", "").Trim() + "' ) ";
        conn.Open();
        try
        {
            cmd.ExecuteNonQuery();
        }
        catch
        {

        }
        conn.Close();
        return originalUserOpenId.Trim();
    }
开发者ID:cangjie,项目名称:lq_yeepay,代码行数:27,代码来源:Util.cs

示例3: ProcessRequest

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string flag = context.Request["flag"].ToString();
            string struid = context.Session["ID"].ToString();
            string strSQL = "update dbo.tabUsers set ";
            string strDataConn = ConfigurationManager.ConnectionStrings["SQLDataConnStr"].ConnectionString;
            SqlConnection dataConn = new SqlConnection(strDataConn);

            if (flag == "1")
            {
                string strusername = context.Request["username"].ToString();
                string strutell = context.Request["utell"].ToString();
                string struemail = context.Request["uemail"].ToString();
                strSQL += "UserName = '" + strusername + "',"+" UserTel = '"+strutell+"',"+"UserEmail = '"+struemail+"' where ID = '"+struid+"'";
                SqlCommand command = new SqlCommand(strSQL, dataConn);
                dataConn.Open();
                command.ExecuteNonQuery();
                dataConn.Close();
                context.Response.Write("OK");
            }
            else if (flag == "2")
            {
                string strpw = context.Request["upassword"].ToString();
                strSQL +=  "UserPW = '" + strpw + "' where UserID = '" + struid + "'";
                SqlCommand command = new SqlCommand(strSQL, dataConn);
                dataConn.Open();
                command.ExecuteNonQuery();
                dataConn.Close();
                context.Response.Write("OK");
            }
        }
开发者ID:JohnToCoder,项目名称:CMG,代码行数:32,代码来源:editPersonal.ashx.cs

示例4: ButtonEnviar_Click

        protected void ButtonEnviar_Click(object sender, EventArgs e)
        {
            try
            {
                SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["RegistroConnectionString"].ConnectionString);
                conn.Open();
                String contar_mensajes = "select count(*) from Mensaje_privado";
                SqlCommand command = new SqlCommand(contar_mensajes, conn);
                int contador = Convert.ToInt32(command.ExecuteScalar().ToString());
                conn.Close();

                conn.Open();
                String enviar_mensaje = "insert into Mensaje_privado (id_mensaje, id_remitente, id_buzon, leido, mensaje, asunto, fecha_de_envio) values (" + contador + ", " + Bandeja_Entrada.id_usuario + ", " + Bandeja_Entrada.id_destino + ", " + 0 + ", '" + TextBoxEM.Text + "', '" + LabelAsunto.Text + "', CURRENT_TIMESTAMP)";
                command = new SqlCommand(enviar_mensaje, conn);
                command.ExecuteNonQuery();
                Response.Write("Mensaje enviado!");
                Panel1.Visible = false;
                ButtonVolver.Visible = true;

                conn.Close();
            }
            catch (Exception ex)
            {
            }
        }
开发者ID:Navilat,项目名称:Tarea2,代码行数:25,代码来源:Mensaje_privado.aspx.cs

示例5: btnSubmit_Click

        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            DataTable dt = new DataTable();
            DataTable dtNew = new DataTable();
            using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString))
            {
                using (SqlCommand cmd = new SqlCommand("select * from all_triathlon_timing", con))
                {
                    con.Open();
                    SqlDataAdapter da = new SqlDataAdapter(cmd);
                    da.Fill(dt);
                    con.Close();

                    int count = dt.Rows.Count;
                    if (count != 0)
                    {

                        using (SqlCommand cmdNew = new SqlCommand("select GUID from all_triathlon_timing where BIBNumber='" + txt123Bib.Text.Trim() + "'", con))
                        {
                            con.Open();
                            SqlDataAdapter daNew = new SqlDataAdapter(cmdNew);
                            daNew.Fill(dtNew);

                            string abc = dtNew.Rows[0][0].ToString();
                            Response.Redirect("GetCertificate.aspx?abc=" + abc);
                        }
                    }
                }
            }
        }
开发者ID:rakeshctc,项目名称:ctcpg,代码行数:30,代码来源:GetBIB.aspx.cs

示例6: GetData

        public IEnumerable<Message> GetData()
        {
            using (var connection = new SqlConnection(ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString))
            {
                connection.Open();
                using (SqlCommand command = new SqlCommand("SELECT [ID], [Date], [Message] FROM [dbo].[Messages]", connection))
                {
                    command.Notification = null;

                    SqlDependency dependency = new SqlDependency(command);
                    dependency.OnChange += DependencyOnChange;

                    if (connection.State == ConnectionState.Closed)
                        connection.Open();

                    using (var reader = command.ExecuteReader())
                        return reader.Cast<IDataRecord>()
                            .Select(x => new Message()
                            {
                                ID = x.GetInt32(0),
                                Date = x.GetDateTime(1),
                                Text = x.GetString(2)
                            }).ToList();
                }
            }
        }
开发者ID:vmeln,项目名称:signalr-scaling,代码行数:26,代码来源:Message.cs

示例7: onload

        private void onload()
        {
            string strSQLconnection = @"Data Source=(LocalDb)\v11.0;AttachDbFilename=|DataDirectory|\aviation.mdf; Trusted_Connection=True;User Instance=True";
            SqlConnection sqlConnection = new SqlConnection(strSQLconnection);
            SqlCommand sqlCommand = new SqlCommand("SELECT p.username,p.nama,p.jawatan,p.bahagian,p.telefon_bimbit,p.telefon_pejabat,p.email FROM profil_pegawai p, supervisor s WHERE p.username = s.ic ORDER BY p.nama", sqlConnection);

                try
                {
                    if (sqlConnection.State.Equals(ConnectionState.Open))
                        sqlConnection.Close();

                    if (sqlConnection.State.Equals(ConnectionState.Closed))
                        sqlConnection.Open();

                    SqlDataAdapter mySqlAdapter = new SqlDataAdapter(sqlCommand);
                    DataSet myDataSet = new DataSet();
                    mySqlAdapter.Fill(myDataSet);

                    gridpenyelia.DataSource = myDataSet;
                    gridpenyelia.DataBind();

                    if (sqlConnection.State.Equals(ConnectionState.Open))
                        sqlConnection.Close();

                    if (sqlConnection.State.Equals(ConnectionState.Closed))
                        sqlConnection.Open();
                }
                catch (SqlException ex)
                {
                }
                finally
                {

                }
        }
开发者ID:nurul98,项目名称:aviation,代码行数:35,代码来源:senaraipenyelia.aspx.cs

示例8: listBox1_Click

        private void listBox1_Click(object sender, EventArgs e)
        {
            string strTableName = this.listBox1.SelectedValue.ToString();//获取数据表名称
            using (SqlConnection con = new SqlConnection(//创建数据库连接对象
 @"server=(local);uid=sa;Pwd=6221131;database='" + strDatabase + "'"))
            {
                string strSql =//创建SQL字符串
                    @"select  name 字段名, xusertype 类型编号, length 长度 into hy_Linshibiao 
from  syscolumns  where id=object_id('" + strTableName + "') ";
                strSql +=//添加字符串信息
@"select name 类型,xusertype 类型编号 into angel_Linshibiao from 
systypes where xusertype in (select xusertype 
from syscolumns where id=object_id('" + strTableName + "'))";
                con.Open();//打开数据库连接
                SqlCommand cmd = new SqlCommand(strSql, con);//创建命令对象
                cmd.ExecuteNonQuery();//执行SQL命令
                con.Close();//关闭数据库连接
                SqlDataAdapter da = new SqlDataAdapter(//创建数据适配器
                    @"select 字段名,类型,长度 from 
hy_Linshibiao t,angel_Linshibiao b where t.类型编号=b.类型编号", con);
                DataTable dt = new DataTable();//创建数据表
                da.Fill(dt);//填充数据表
                this.dataGridView1.DataSource = dt.DefaultView;//设置数据源
                SqlCommand cmdnew = new SqlCommand(//创建命令对象
                    "drop table hy_Linshibiao,angel_Linshibiao", con);
                con.Open();//打开数据库连接
                cmdnew.ExecuteNonQuery();//执行SQL命令
                con.Close();//关闭数据库连接
            }
        }
开发者ID:mahuidong,项目名称:c-1200-II,代码行数:30,代码来源:Frm_Main.cs

示例9: BindDDL2

        protected void BindDDL2()
        {
            SqlConnection con = new SqlConnection(constr);
            con.Open();
            SqlCommand cmd1 = new SqlCommand("select DISTINCT s.ProjectID,s.ProjectnameTH from StudentProject s join CPE02 c on s.ProjectID = c.ProjectID where s.Advisorusername='" + Session["Username"].ToString() + "'", con);
            SqlDataReader reader1 = cmd1.ExecuteReader();
            int count = 0;
            while (reader1.Read())
            {
                count++;
            }
            con.Close();
            if (count == 0)
            {
                DropDownList2.Items.Add(new ListItem("ไม่มีข้อมูล", "none"));
                DropDownList2.Items.FindByValue("none").Selected = true;
            }
            else
            {
                DataTable dt = new DataTable();

                SqlCommand cmdxx = new SqlCommand("select DISTINCT s.ProjectID,s.ProjectnameTH from StudentProject s join CPE02 c on s.ProjectID = c.ProjectID where s.Advisorusername='" + Session["Username"].ToString() + "'", con);
                con.Open();
                dt.Load(cmdxx.ExecuteReader());
                con.Close();

                DropDownList2.DataSource = dt;
                DropDownList2.DataTextField = "ProjectnameTH";
                DropDownList2.DataValueField = "ProjectID";
                DropDownList2.DataBind();
                DropDownList2.Items.Add(new ListItem("Choose", "choose"));
                DropDownList2.Items.FindByValue("choose").Selected = true;
            }
        }
开发者ID:smnodame,项目名称:swe-file,代码行数:34,代码来源:Tcpe02.aspx.cs

示例10: Main

        static void Main(string[] args)
        {
            String sc = @"Data Source=.\sqlexpress;Initial Catalog=MASTER;Integrated Security=true;Connect Timeout=1;Pooling=false";

            SqlConnection c = null;

            try
            {
                c = new SqlConnection(sc);

                c.Open();
                c.Open();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.GetType().Name);
                Console.WriteLine(ex.Message);
                Console.WriteLine(ex.Source);
            }
            finally
            {
                if (/*c != null &&*/ c.State != ConnectionState.Closed)
                    c.Close();

                Console.ReadKey();
            }
        }
开发者ID:50minutos,项目名称:VS2010,代码行数:27,代码来源:Program.cs

示例11: run

        public void run()
        {
            string liveConString = ConfigurationManager.AppSettings["dailyconstring"];
            string reportConString = ConfigurationManager.AppSettings["dailyconstringReportingServer"];
            string EngageConString = ConfigurationManager.AppSettings["engageconstring"];
            string VidConString = ConfigurationManager.AppSettings["dailyconstringReportingServer"];
            string targetMonth = ConfigurationManager.AppSettings["TargetMonth"];
            string previousMonth = ConfigurationManager.AppSettings["PreviousMonth"];
            string monthEndSubsUpdateQueries = ConfigurationManager.AppSettings["MonthEndSubsUpdateQueries"];//'|' delimited, string replace targetmonth,previousmonth
            //string NowConString = ConfigurationManager.AppSettings[""];
            try
            {
                SqlConnection con = new SqlConnection();
                DataSet dsResult = new DataSet();
                con.ConnectionString = reportConString;
                con.Open();

                SqlCommand cmd = new SqlCommand();
                cmd.CommandTimeout = 1200;
                //cmd.CommandText = @"select case when count(*) =0 then 0 else sum(t.numbers) end from (select isnull(count(distinct u.userid),0) as 'numbers' from users u inner join country c on u.countrycode=c.code inner join gomssubsidiary g on c.gomssubsidiaryid=g.gomssubsidiaryid where cast(registrationdate as date) = '" + traverserDate.Date.ToString("yyyy-MM-dd") + @"'  and case when g.gomssubsidiaryid=6 or g.gomssubsidiaryid=8 or g.gomssubsidiaryid=9 then 'GLB : EU' else g.code end = 'GLB : " + region + @"' group by case when g.gomssubsidiaryid=6 or g.gomssubsidiaryid=8 or g.gomssubsidiaryid=9 then 'GLB : EU' else g.code end) as t union all select case when count(*) =0 then 0 else sum(t.numbers) end from (select isnull(count(distinct er.userid),0) as 'numbers' from entitlementrequests er  inner join users u on u.userid=er.userid inner join country c on u.countrycode=c.code inner join gomssubsidiary g on c.gomssubsidiaryid=g.gomssubsidiaryid inner join transactions t on er.userid=t.userid left outer join ppctype ppc on left(t.reference,2)=ppc.ppcproductcode left join purchaseitems pu on pu.entitlementrequestid = er.entitlementrequestid where er.productid  in (1,3,4,5,6,7,8,9) and er.source <>'TFC.tv Everywhere' and cast(er.enddate as date)>='" + traverserDate.AddDays(1).ToString("yyyy-MM-dd") + @"'  and er.daterequested<='" + traverserDate.AddDays(1).ToString("yyyy-MM-dd") + @"'  and (subscriptionppctypeid is null or subscriptionppctypeid not in (2,3,4)) and case when g.gomssubsidiaryid=6 or g.gomssubsidiaryid=8 or g.gomssubsidiaryid=9 then 'GLB : EU' else g.code end = 'GLB : " + region + @"' group by case when g.gomssubsidiaryid=6 or g.gomssubsidiaryid=8 or g.gomssubsidiaryid=9 then 'GLB : EU' else g.code end) as t union all select case when count(*) =0 then 0 else sum(t.numbers) end from (select isnull(count(distinct er.userid),0) as 'numbers' from entitlementrequests er  inner join users u on u.userid=er.userid inner join country c on u.countrycode=c.code inner join gomssubsidiary g on c.gomssubsidiaryid=g.gomssubsidiaryid inner join transactions t on er.userid=t.userid left outer join ppctype ppc on left(t.reference,2)=ppc.ppcproductcode left join purchaseitems pu on pu.entitlementrequestid = er.entitlementrequestid where er.productid  in (1,3,4,5,6,7,8,9) and er.source <>'TFC.tv Everywhere' and cast(er.enddate as date)='" + traverserDate.ToString("yyyy-MM-dd") + @"'  and er.daterequested<='" + traverserDate.AddDays(1).ToString("yyyy-MM-dd") + @"'  and (subscriptionppctypeid is null or subscriptionppctypeid not in (2,3,4)) and case when g.gomssubsidiaryid=6 or g.gomssubsidiaryid=8 or g.gomssubsidiaryid=9 then 'GLB : EU' else g.code end = 'GLB : " + region + @"' group by case when g.gomssubsidiaryid=6 or g.gomssubsidiaryid=8 or g.gomssubsidiaryid=9 then 'GLB : EU' else g.code end) as t union all select case when count(*) =0 then 0 else sum(t.numbers) end from (select isnull(count(distinct userid),0) as 'numbers' from ( select u.email, er.userid,u.firstname,u.lastname,er.productid,er.enddate,u.countrycode  from entitlementrequests er inner join users u on u.userid=er.userid inner join transactions t on er.userid=t.userid left outer join ppctype ppc on left(t.reference,2)=ppc.ppcproductcode left outer join purchaseitems pu on pu.entitlementrequestid = er.entitlementrequestid where er.productid  in (1,3,4,5,6,7,8,9) and er.source <>'TFC.tv Everywhere' and (subscriptionppctypeid is null or subscriptionppctypeid not in (2,3,4)) and cast(er.daterequested as date)= '" + traverserDate.ToString("yyyy-MM-dd") + @"'  and er.UserId not in( select er.userid from entitlementrequests er inner join users u on u.userid=er.userid inner join transactions t on er.userid=t.userid left outer join ppctype ppc on left(t.reference,2)=ppc.ppcproductcode left outer join purchaseitems pu on pu.entitlementrequestid = er.entitlementrequestid where er.productid  in (1,3,4,5,6,7,8,9) and er.source <>'TFC.tv Everywhere' and (subscriptionppctypeid is null or subscriptionppctypeid not in (2,3,4)) and cast(er.daterequested as date)< '" + traverserDate.ToString("yyyy-MM-dd") + @"'  ) ) as temp inner join country c on c.code=temp.countrycode inner join gomssubsidiary g on c.gomssubsidiaryid=g.gomssubsidiaryid and case when g.gomssubsidiaryid=6 or g.gomssubsidiaryid=8 or g.gomssubsidiaryid=9 then 'GLB : EU' else g.code end = 'GLB : " + region + @"' group by case when g.gomssubsidiaryid=6 or g.gomssubsidiaryid=8 or g.gomssubsidiaryid=9 then 'GLB : EU' else g.code end) as t union all select case when count(*) =0 then 0 else sum(t.numbers) end from (select isnull(count(distinct userid),0) as 'numbers' from ( select u.email, er.userid,u.firstname,u.lastname,er.productid,er.enddate,u.countrycode  from entitlementrequests er inner join users u on u.userid=er.userid inner join transactions t on er.userid=t.userid left outer join ppctype ppc on left(t.reference,2)=ppc.ppcproductcode left outer join purchaseitems pu on pu.entitlementrequestid = er.entitlementrequestid where er.productid  in (1,3,4,5,6,7,8,9) and er.source <>'TFC.tv Everywhere' and (subscriptionppctypeid is null or subscriptionppctypeid not in (2,3,4)) and cast(er.daterequested as date)= '" + traverserDate.ToString("yyyy-MM-dd") + @"'  and er.UserId in( select er.userid from entitlementrequests er inner join users u on u.userid=er.userid inner join transactions t on er.userid=t.userid left outer join ppctype ppc on left(t.reference,2)=ppc.ppcproductcode left outer join purchaseitems pu on pu.entitlementrequestid = er.entitlementrequestid where er.productid  in (1,3,4,5,6,7,8,9) and er.source <>'TFC.tv Everywhere' and (subscriptionppctypeid is null or subscriptionppctypeid not in (2,3,4)) and cast(er.daterequested as date)< '" + traverserDate.ToString("yyyy-MM-dd") + @"'  ) ) as temp inner join country c on c.code=temp.countrycode inner join gomssubsidiary g on c.gomssubsidiaryid=g.gomssubsidiaryid and case when g.gomssubsidiaryid=6 or g.gomssubsidiaryid=8 or g.gomssubsidiaryid=9 then 'GLB : EU' else g.code end = 'GLB : " + region + @"' group by case when g.gomssubsidiaryid=6 or g.gomssubsidiaryid=8 or g.gomssubsidiaryid=9 then 'GLB : EU' else g.code end) as t union all select case when count(*) =0 then 0 else sum(t.numbers) end from (select isnull(count(distinct er.userid),0) as 'numbers' from entitlementrequests er inner join users u on u.userid=er.userid inner join country c on c.code=u.countrycode inner join gomssubsidiary g on c.gomssubsidiaryid=g.gomssubsidiaryid inner join products p on p.productid=er.productid inner join transactions t on er.userid=t.userid left outer join ppctype ppc on left(t.reference,2)=ppc.ppcproductcode left join purchaseitems pu on pu.entitlementrequestid = er.entitlementrequestid where (p.alacartesubscriptiontypeid is not null or er.productid=2) and er.source <>'TFC.tv Everywhere' and cast(er.enddate as date)>='" + traverserDate.AddDays(1).ToString("yyyy-MM-dd") + @"'  and er.daterequested<='" + traverserDate.AddDays(1).ToString("yyyy-MM-dd") + @"'  and (subscriptionppctypeid is null or subscriptionppctypeid not in (2,3,4)) and case when g.gomssubsidiaryid=6 or g.gomssubsidiaryid=8 or g.gomssubsidiaryid=9 then 'GLB : EU' else g.code end = 'GLB : " + region + @"' group by case when g.gomssubsidiaryid=6 or g.gomssubsidiaryid=8 or g.gomssubsidiaryid=9 then 'GLB : EU' else g.code end) as t union all select case when count(*) =0 then 0 else sum(t.numbers) end from (select isnull(count(distinct userid),0) as 'numbers' from ( select u.email, er.userid,u.firstname,u.lastname,er.productid,er.enddate,u.countrycode from entitlementrequests er  inner join users u on u.userid=er.userid inner join products p on p.productid=er.productid inner join transactions t on er.userid=t.userid left outer join ppctype ppc on left(t.reference,2)=ppc.ppcproductcode left outer join purchaseitems pu on pu.entitlementrequestid = er.entitlementrequestid where (p.alacartesubscriptiontypeid is not null or er.productid=2) and er.source <>'TFC.tv Everywhere' and (subscriptionppctypeid is null or subscriptionppctypeid not in (2,3,4)) and cast(er.daterequested as date)= '" + traverserDate.ToString("yyyy-MM-dd") + @"'  ) as temp inner join country c on c.code=temp.countrycode inner join gomssubsidiary g on c.gomssubsidiaryid=g.gomssubsidiaryid where case when g.gomssubsidiaryid=6 or g.gomssubsidiaryid=8 or g.gomssubsidiaryid=9 then 'GLB : EU' else g.code end = 'GLB : " + region + @"' group by case when g.gomssubsidiaryid=6 or g.gomssubsidiaryid=8 or g.gomssubsidiaryid=9 then 'GLB : EU' else g.code end) as t union all select case when count(*) =0 then 0 else sum(t.numbers) end from (select isnull(count(distinct er.userid),0) as 'numbers' from entitlementrequests er inner join users u on u.userid=er.userid inner join country c on c.code=u.countrycode inner join gomssubsidiary g on c.gomssubsidiaryid=g.gomssubsidiaryid inner join products p on p.productid=er.productid inner join transactions t on er.userid=t.userid left outer join ppctype ppc on left(t.reference,2)=ppc.ppcproductcode left outer join purchaseitems pu on pu.entitlementrequestid = er.entitlementrequestid where (p.alacartesubscriptiontypeid is not null or er.productid=2) and er.source <>'TFC.tv Everywhere' and cast(er.enddate as date)='" + traverserDate.ToString("yyyy-MM-dd") + @"'  and er.daterequested<='" + traverserDate.AddDays(1).ToString("yyyy-MM-dd") + @"'  and (subscriptionppctypeid is null or subscriptionppctypeid not in (2,3,4)) and case when g.gomssubsidiaryid=6 or g.gomssubsidiaryid=8 or g.gomssubsidiaryid=9 then 'GLB : EU' else g.code end = 'GLB : " + region + @"' group by case when g.gomssubsidiaryid=6 or g.gomssubsidiaryid=8 or g.gomssubsidiaryid=9 then 'GLB : EU' else g.code end) as t";

                cmd.Connection = con;
                con.Open();
                cmd.ExecuteNonQuery();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
开发者ID:agentvnod,项目名称:tfctvoldcode,代码行数:30,代码来源:QueryAutomation.cs

示例12: CreateGetClothingProcedureIfNull

        public void CreateGetClothingProcedureIfNull()
        {
            using (SqlConnection con = new SqlConnection(Settings.AdventureWorksConStr))
            {
                SqlCommand checkIfProcExists = new SqlCommand();
                checkIfProcExists.CommandText = "IF (OBJECT_ID('GetProductsByGender') IS NOT NULL) " +
                                                "DROP PROCEDURE GetProductsByGender " +
                                                "";
                checkIfProcExists.Connection = con;

                con.Open();

                using (SqlDataReader dr = checkIfProcExists.ExecuteReader())
                {
                }

                con.Close();

                SqlCommand command = new SqlCommand();
                command.CommandText = "CREATE PROCEDURE GetProductsByGender (@strGender varchar(5)) " +
                                      "AS " +
                                      "SELECT ProductModelID, Name " +
                                      "FROM Production.ProductModel " +
                                      "WHERE Name LIKE @strGender";
                command.Connection = con;

                con.Open();

                using (SqlDataReader dr = command.ExecuteReader())
                {
                }
            }
        }
开发者ID:ciaochow,项目名称:ADO.Net-Demo,代码行数:33,代码来源:AW_ProductModelRepo.cs

示例13: GetMessagesChat

        // Lấy Messages cần gửi
        public List<DiscussMessage> GetMessagesChat()
        {
            var messageChat = new List<DiscussMessage>();
            using (var connection = new SqlConnection(_connString))
            {
                connection.Open();
                using (var command = new SqlCommand(@"SELECT dbo.Messages.Id, dbo.Messages.[Content], dbo.Messages.SenderId, dbo.Messages.SendDate, dbo.Messages.Type
                                                            FROM  dbo.Messages
                                                            WHERE dbo.Messages.Sent = 'N' ORDER BY dbo.Messages.SendDate ASC", connection))
                {
                    command.Notification = null;
                    if (connection.State == ConnectionState.Closed)
                        connection.Open();
                    var reader = command.ExecuteReader();

                    while (reader.Read())
                    {
                        messageChat.Add(item: new DiscussMessage
                        {
                            Id = reader["Id"].ToString(),
                            Content = reader["Content"].ToString(),
                            SenderId = reader["SenderId"].ToString(),
                            UserName = "",
                            SendDate = reader["SendDate"].ToString(),
                            Type = reader["Type"].ToString(),
                            GroupId = ""
                        });
                    }
                }
            }

            return messageChat;
        }
开发者ID:vanan08,项目名称:ADSoft,代码行数:34,代码来源:1448034831$DiscussMessageRepository.cs

示例14: Insert

 public mobile_employees Insert(mobile_employees id)
 {
     string ConnectionString = IDManager.connection();
     SqlConnection con = new SqlConnection(ConnectionString);
     try
     {
     con.Open();
     SqlCommand cmd = new SqlCommand("SP_DMCS_INSERT_MOBILE_EMPLOYEES", con);
     cmd.CommandType = System.Data.CommandType.StoredProcedure;
     cmd.Parameters.AddWithValue("@mobile_unit_id", id.mobile_unit_id);
     cmd.Parameters.AddWithValue("@employee_id", id.employee_id);
     cmd.ExecuteReader();
     con.Close();
     con.Open();
     cmd = new SqlCommand("SP_DMCS_GET_MOBILE_EMPLOYEES", con);
     cmd.CommandType = System.Data.CommandType.StoredProcedure;
     cmd.Parameters.AddWithValue("@mobile_unit_id", id.mobile_unit_id);
     cmd.Parameters.AddWithValue("@employee_id", id.employee_id);
     SqlDataReader rdr = cmd.ExecuteReader();
     if (rdr.HasRows)
     {
         rdr.Read();
         id.mobile_employee_id = rdr.GetInt32(0);
     }
     }
     catch (Exception ex)
     {
     id.SetColumnDefaults();
     }
     finally
     {
     con.Close();
     }
     return id;
 }
开发者ID:ManigandanS,项目名称:Disaster-Management-Communication-System,代码行数:35,代码来源:mobile_employees.cs

示例15: CreateAccount

        //The DAL managers contain methods that assign parameters to Procedures Stored
        //in the Database. each method return relevant infromation - dataSets that binds
        //to grids, objects and values to be assigned and used and true/false values so
        //show if information in the DB has been entered/replaced/updated
        public bool CreateAccount(Customer newCustomer, Account newAccount)
        {
            bool userCreated = false, accountCreated = false;

            using (cxn = new SqlConnection(this.ConnectionString))
            {
                using (cmd = new SqlCommand("spCreateCustomer", cxn))
                {
                    cmd.CommandType = CommandType.StoredProcedure;

                    cmd.Parameters.Add("@FirstName", SqlDbType.NVarChar, 50).Value = newCustomer.FirstName;
                    cmd.Parameters.Add("@Surname", SqlDbType.NVarChar, 50).Value = newCustomer.Surname;
                    cmd.Parameters.Add("@Email", SqlDbType.NVarChar, 50).Value = newCustomer.Email;
                    cmd.Parameters.Add("@Phone", SqlDbType.NVarChar, 50).Value = newCustomer.Phone;
                    cmd.Parameters.Add("@AddressLine1", SqlDbType.NVarChar, 50).Value = newCustomer.AddressLine1;
                    cmd.Parameters.Add("@AddressLine2", SqlDbType.NVarChar, 50).Value = newCustomer.AddressLine2;
                    cmd.Parameters.Add("@City", SqlDbType.NVarChar, 50).Value = newCustomer.City;
                    cmd.Parameters.Add("@County", SqlDbType.NVarChar, 50).Value = newCustomer.County;
                    cmd.Parameters.Add("@CustomerID", SqlDbType.Int, 4).Direction = ParameterDirection.Output;
                    cmd.Parameters.Add("@OnlineCustomer", SqlDbType.Bit).Value = newCustomer.OnlineCustomer;

                    cxn.Open();
                    int rows = cmd.ExecuteNonQuery();
                    cxn.Close();

                    if (rows > 0)
                    {
                        newCustomer.CustomerID = Convert.ToInt32(cmd.Parameters["@CustomerID"].Value);
                        newAccount.CustomerID = newCustomer.CustomerID;
                        userCreated = true;
                    }
                }

                using (cmd = new SqlCommand("spCreateAccount", cxn))
                {
                    cmd.CommandType = CommandType.StoredProcedure;

                    cmd.Parameters.Add("@AccountType", SqlDbType.NVarChar, 50).Value = newAccount.AccountType;
                    cmd.Parameters.Add("@SortCode", SqlDbType.Int, 8).Value = newAccount.SortCode;
                    cmd.Parameters.Add("@InitialBalance", SqlDbType.Int, 8).Value = newAccount.Balance;
                    cmd.Parameters.Add("@OverDraft", SqlDbType.Int, 8).Value = newAccount.OverDraftLimit;
                    cmd.Parameters.Add("@CustomerID", SqlDbType.Int, 4).Value = newAccount.CustomerID;
                    cmd.Parameters.Add("@AccountNumber", SqlDbType.Int, 8).Direction = ParameterDirection.Output;

                    cxn.Open();
                    int rows = cmd.ExecuteNonQuery();
                    cxn.Close();

                    if (rows > 0)
                    {
                        newAccount.AccountNumber = Convert.ToInt32(cmd.Parameters["@AccountNumber"].Value);
                        accountCreated = true;
                    }
                }
                if (userCreated && accountCreated)
                    return true;
                else
                    return false;
            }
        }
开发者ID:robbiegleeson,项目名称:3_Tier_Banking_Application,代码行数:64,代码来源:AccountDALManager.cs


注:本文中的System.Data.SqlClient.SqlConnection.Open方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。