10月 25, 2014

免用SQL的SqlDataAdapter的新增修改和刪除

        Dim dt As New DataTable
        Using cn As New SqlConnection(conn)
            Dim rr$ = "select * from city where id=@id"

            Dim cmds As New SqlDataAdapter(rr, cn)
            cmds.SelectCommand.Parameters.AddWithValue("id", 8)
            cmds.Fill(dt)
            Dim cb As New SqlCommandBuilder(cmds)
            '新增
            'Dim dr As DataRow = dt.NewRow
            'dr("id") = 9
            'dr("pp") = "hh"
            'dt.Rows.Add(dr)
            'dt.Rows.Add(8, "ert")'偷懶用
            '修改
            'dt.Rows(0)("city") = "666"'偷懶用
            'For Each dr As DataRow In dt.Select("id=" & 8)
            '    dr("kk") = "hello"
            'Next
            '刪除
            'dt.Rows(0).Delete()'偷懶用
            'For Each dr As DataRow In dt.Select("id=" & 8)
            '    dr.Delete()
            'Next
            cmds.Update(dt)
            cmds.Dispose()
        End Using
        GridView1.DataSource = dt
        GridView1.DataBind()

8月 25, 2014

獲得system權限

因为需要对注册表进行操作,才发现原来管理员的权限也是不够的。打开注册表下一些特殊文件夹的权限一看,发现只有SYSTEM这个身份具备所有权限。由于其他所有身份删除注册表都是被拒绝的,所以,需要切换到SYSTEM身份下。 网上又使用at指令进行操作的,发现在win7下不可行,早已升级了。 最后在管理员权限下打开cmd,输入以下命令 sc Create SuperCMD binPath= "cmd /K start" type= own type= interact sc start SuperCMD 然后win7下就会弹出一个消息,询问是否现在查看,点击立即查看,窗口会跳转到另外一个界面,这个界面就是用System身份打开的cmd,具备所有权限,然后用一下命令删除注册表的指定目标文件夹,OK reg delete "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\USB\VID_093A&PID_2521" /f whoami指令可以看當前用戶

4月 02, 2014

MVC 用表單送資料給資料庫

首先是View
    @{Html.BeginForm("postdata", "home", FormMethod.Post);}
    @Html.Label("hh")<br>
    First name: <input id="textbox1" name="name1" type="text" value=""><br>
    Last name:  @Html.TextBox("name2", "", new {id="textbox2" })
    <br>
    <input id="Submit11" type="submit" value="submit" />
    @{Html.EndForm();}
再來是controll
        [HttpPost]
        public ActionResult postdata(int name1,int name2)
        {
            //ViewData["result"] = name1 + name2;
            //ViewBag.da = name1 + name2;
            int hh = name1 + name2;
            ty.see56(hh);
            return RedirectToAction("Index");
        }
接著是Model
 public int see56(int vlk)
        {

            SqlDataSource sds = new SqlDataSource();
            sds.ConnectionString = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;
            sds.UpdateCommand = "update item set mp=@mp where id=1";
            sds.UpdateParameters.Add(new Parameter("mp",DbType.String,vlk.ToString()));
            sds.Update();
            
           
            return 0;
            //return dv.Table.Rows[2].ItemArray[1].ToString();
        }
大功告成!

4月 01, 2014

設計換行和超聯結

 Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim Label1 As Label = FormView1.FindControl("Label1")
        'Dim b As String = vbNewLine
        'Replace(a.Text, Chr(10), "<br />")
        If Label1 IsNot Nothing Then

            Label1.Text = Replace(Label1.Text, vbNewLine, "<br />")

        End If

        ads_count.Update()

    End Sub

    

    Protected Sub HyperLink2_PreRender(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim a As HyperLink = FormView1.FindControl("HyperLink2")
        'Server.Transfer("./upload/" + a.Text)
        'Response.Redirect("./upload/" + a.Text)
        Dim b As String = "./upload/" + a.Text

        a.NavigateUrl = b

    End Sub

3月 31, 2014

MVC 檔案上傳fileupload

Protected Sub Button4_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        Try

            
            Dim a2 As FileUpload = FormView1.FindControl("FileUpload2")
            a2.SaveAs(Server.MapPath("./upload/") + a2.FileName)

            Dim c2 As Label = FormView1.FindControl("Label444")
            c2.Text = a2.FileName
            a2.Enabled = False

            Dim d2 As Button = FormView1.FindControl("Button4")
            d2.Enabled = False
            Label2.Text = "上傳成功!!"
        Catch ex As Exception
            Label2.Text = ex.ToString()
        End Try
    End Sub
首先在VIEW中輸入程式碼:
<form action="@Url.Action("MultiUpload")" method="post" enctype="multipart/form-data">
    <input id="File1" type="file" name="files"/>
    <input id="File2" type="file" name="files"/>
    <input id="Submit1" type="submit" value="submit" />
    <input id="Reset2" type="reset" value="reset" />
</form>
接著是controll中的files必須對應到input的tag中的name即可
[HttpPost]
        public ActionResult MultiUpload(IEnumerable<HttpPostedFileBase> files)
        {
            foreach (var file in files)
            {
                if (file != null && file.ContentLength > 0)
                {
                    
                    var path = Server.MapPath("~/App_Data/") + file.FileName;
                    file.SaveAs(path);
                }
            }
            return RedirectToAction("Index");
            
        }