Database connection using the Add Parameter

27 五月, 2009 at 12:06 下午 發表留言

Database connection using the Add Parameter

SqlConnection sqlcon;
string strCon = “connection string";           

           string sql = @"SELECT * FROM [Unsubscribe] WHERE ([EMAIL] LIKE ‘%’ + @EMAIL + ‘%’ OR @EMAIL = “) AND ([ACTIVE] = @ACTIVE)";
            sqlcon = new SqlConnection(strCon);

            SqlCommand cmds = new SqlCommand(sql, sqlcon);
            cmds.Parameters.AddWithValue(“@ACTIVE", actcount);
            cmds.Parameters.AddWithValue(“@EMAIL", txtSearch.Text);
            DataSet dss = new DataSet();
            SqlDataAdapter daa = new SqlDataAdapter(cmds);

            daa.Fill(dss);

            DataView view4 = dss.Tables[0].DefaultView;
            string sort4 = (string)ViewState[“SortOrder"] + " " + (string)ViewState[“OrderDire"];
            view4.Sort = sort4;

            GridView1.DataKeyNames = new string[] { “UID" };
            GridView1.DataSource = view4;
            GridView1.DataBind();

++++++++++++++++++++++++++++++++++++++++++++++++++++++

        string conString = @"connection string";
        OleDbConnection conn = new OleDbConnection(conString);
        conn.Open();

        OleDbCommand cmd = new OleDbCommand(“SELECT * FROM [category] WHERE id = @id", conn);
        cmd.Parameters.AddWithValue(“@id", userId);

        DataSet ds = new DataSet();
        OleDbDataAdapter sa = new OleDbDataAdapter(cmd);
        sa.Fill(ds);

        if (ds.Tables[0].Rows.Count > 0)
        {
            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                Label2.Text = dr[“name"].ToString();
            }
        }
       

++++++++++++++++++++++++++++++++++++++++++++++++++++++

 

                OleDbCommand cmd1 = new OleDbCommand(“Select COUNT(product_id) FROM [stock] WHERE product_id = @id", conn);
                cmd1.Parameters.AddWithValue(“@id", userId);
                int getcount = Convert.ToInt32(cmd1.ExecuteScalar());
                if (getcount > 0)
                {
                    Label6.Text = “Yes";

                }
                else
                {
                    Label6.Text = “No";
                }

                Session[“pstock"] = Label6.Text;

 

+++++++++++++++++++++++++++++++++++++++++++++++++++++++

        int getqty = Int32.Parse(DropDownList1.SelectedValue);
        string conString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Inetpub\assign1\App_Data\furniturestore.mdb";

        OleDbConnection conn1 = new OleDbConnection(conString);
        conn1.Open();

        OleDbCommand cmd1 = new OleDbCommand(“Select price FROM [products] WHERE id = @id", conn1);
        cmd1.Parameters.AddWithValue(“@id", userId);

        int price = Convert.ToInt32(cmd1.ExecuteScalar());

        Session[“oprice"] = price * getqty;

        conn1.Close();
        int calprice = int.Parse(getprice) * getqty;

        Response.Redirect(“orderreceived.aspx?totalprice="+ calprice +"");

Entry filed under: ASP.NET, Database.

製作一個favicon.ico圖示(係url show 出來個d) pass value in query string via grid view

發表迴響

在下方填入你的資料或按右方圖示以社群網站登入:

WordPress.com 標誌

您的留言將使用 WordPress.com 帳號。 登出 /  變更 )

Google photo

您的留言將使用 Google 帳號。 登出 /  變更 )

Twitter picture

您的留言將使用 Twitter 帳號。 登出 /  變更 )

Facebook照片

您的留言將使用 Facebook 帳號。 登出 /  變更 )

連結到 %s

Trackback this post  |  Subscribe to the comments via RSS Feed


近期文章


%d 位部落客按了讚: