输入字符串的格式不正确。网格视图

时间:2016-02-17 16:42:40

标签: vb.net gridview

我正在做我的学校工作,但我的代码有一些错误,但我在我的其他文件中运行这个类似的代码,没有问题。希望你们能帮助我。这是关于获取多数据库名称

<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="false" Width="100%" AllowPaging="true" OnPageIndexChanging="OnPageIndexChanging2" PageSize="3" CssClass="Grid" DataKeyNames="id, tripidtaking, reqid" >
                    <Columns>
                        <asp:BoundField DataField="fname" />
                        <asp:BoundField DataField="reqid" HeaderText="Req ID" />
                        <asp:BoundField DataField="tripidtaking" HeaderText="trip ID" />
                        <asp:BoundField DataField="id" HeaderText="trip ID" />
                        <asp:BoundField DataField="startptname" HeaderText="Origin" />
                        <asp:BoundField DataField="endptname" HeaderText="Destination" />
                        <asp:BoundField DataField="givendate" HeaderText="Date" />
                        <asp:BoundField DataField="starttime" HeaderText="Agreed Time" />
                        <asp:BoundField DataField="numperson" HeaderText="NoOfPpl" />
                        <asp:BoundField DataField="Recurring" HeaderText="Whether Recurring" />
                        <asp:BoundField DataField="day" HeaderText="Selected Day" />
                        <asp:BoundField DataField="usertype" HeaderText="Type" />
                        <asp:BoundField DataField="Cfname" HeaderText="Driver Name" />
                        <asp:BoundField DataField="cid" HeaderText="Driver ID" />
                        <asp:BoundField DataField="" HeaderText="" />
                        <asp:BoundField DataField="" HeaderText="" />
                    </Columns>
                </asp:GridView>

Protected Sub GridView2_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView2.RowDataBound

    Dim row As GridViewRow = e.Row

    If row.RowType = DataControlRowType.DataRow Then

        Dim lb2 As New LinkButton()
        lb2.ID = "lbCancel"
        lb2.Text = "Cancel"
        lb2.CommandName = "CancelRow"
        lb2.CommandArgument = DataBinder.Eval(row.DataItem, "ID")

        row.Cells(14).Controls.Add(lb2)

        If row.Cells(13).Text = reqid Then

            Dim lb As New LinkButton()
            lb.ID = "lbEnd"
            lb.Text = "End"
            lb.CommandName = "EndRow"
            lb.CommandArgument = DataBinder.Eval(row.DataItem, "tripidtaking") + "," + DataBinder.Eval(row.DataItem, "reqid")

            row.Cells(15).Controls.Add(lb)

        End If
    End If

End Sub

Protected Sub GridView2_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles GridView2.RowCommand

    Dim reqid As String = Session("reqid")
    Dim arguments As String() = e.CommandArgument.ToString().Split(New Char() {","})

    If (e.CommandName = "CancelRow") Then

        Dim ID As String = arguments(0)

        myconnection.Open()
        Using mycommand As SqlCommand = myconnection.CreateCommand
            mycommand.CommandText = "delete from ongoing_trips where id=" + ID
            mycommand.ExecuteNonQuery()
        End Using
        myconnection.Close()

        Response.Redirect("mytrip.aspx")
        'Response.Write("<script language='javascript'> alert(" + ID + "); </script>")


    ElseIf (e.CommandName = "EndRow") Then

        Dim rid As String = arguments(2)
        Dim tripIDtaking As String = arguments(1)

        Dim uid As String = ""
        Dim uname As String = ""
        Dim fname As String = ""
        Dim lname As String = ""
        Dim tid As String = ""
        Dim status As String = ""
        Dim stptname As String = ""
        Dim edptname As String = ""
        Dim gdate As String = ""
        Dim stime As String = ""
        Dim etime As String = ""
        Dim nop As String = ""
        Dim uty As String = ""
        Dim cfname As String = ""
        Dim cid As String = ""
        Dim recur As Char = ""

        Using con As New SqlConnection(connString)
            Using cmd As New SqlCommand("SELECT * FROM ongoing_trips inner JOIN accounts ON ongoing_trips.reqid=accounts.userid inner join trips on ongoing_trips.tripidtaking=trips.tripid where (ongoing_trips.status='ACTIVE' AND ongoing_trips.reqid='" + rid + "') and ongoing_trips.tripidtaking='" + tripIDtaking + "'")
                cmd.Connection = con
                con.Open()
                Dim reader As SqlDataReader = cmd.ExecuteReader()
                While reader.Read()
                    uid = Convert.ToString(reader("userid").ToString())
                    uname = Convert.ToString(reader("uname").ToString())
                    fname = Convert.ToString(reader("fname").ToString())
                    lname = Convert.ToString(reader("lname").ToString())
                    tid = Convert.ToString(reader("tripid").ToString())
                    stptname = Convert.ToString(reader("startptname").ToString())
                    edptname = Convert.ToString(reader("endptname").ToString())
                    gdate = Convert.ToString(reader("givendate").ToString())
                    stime = Convert.ToString(reader("starttime").ToString())
                    etime = Convert.ToString(reader("endtime").ToString())
                    nop = Convert.ToString(reader("numperson").ToString())
                    uty = Convert.ToString(reader("usertype").ToString())
                    recur = Convert.ToString(reader("recurring").ToString())
                    cfname = Convert.ToString(reader("cfname").ToString())
                    cid = Convert.ToString(reader("cid").ToString())
                End While
                con.Close()
            End Using
        End Using

        If recur = "Y" Then
            Response.Write("<script language='javascript'> alert('y'); </script>")
        ElseIf recur = "N" Then
            Using con2 As New SqlConnection(connString2)
                con2.Open()
                Using mycommand As SqlCommand = con2.CreateCommand
                    mycommand.CommandText = "insert into trips_history values (@userid, @uname, @fname, @lname, @tripid, 'COMPLETED', @startptname, @endptname, @givendate, @starttime, @endtime, @numperson, @usertype, SYSDATETIME(), @cfname, @cid)"
                    mycommand.Parameters.AddWithValue("@userid", uid)
                    mycommand.Parameters.AddWithValue("@uname", uname)
                    mycommand.Parameters.AddWithValue("@fname", fname)
                    mycommand.Parameters.AddWithValue("@lname", lname)
                    mycommand.Parameters.AddWithValue("@tripid", tid)
                    mycommand.Parameters.AddWithValue("@startptname", stptname)
                    mycommand.Parameters.AddWithValue("@endptname", edptname)
                    mycommand.Parameters.AddWithValue("@givendate", gdate)
                    mycommand.Parameters.AddWithValue("@starttime", stime)
                    mycommand.Parameters.AddWithValue("@endtime", etime)
                    mycommand.Parameters.AddWithValue("@numperson", nop)
                    mycommand.Parameters.AddWithValue("@usertype", uty)
                    mycommand.Parameters.AddWithValue("@cfname", cfname)
                    mycommand.Parameters.AddWithValue("@cid", cid)
                    mycommand.ExecuteNonQuery()
                End Using
                con2.Close()
            End Using

            myconnection.Open()
            Using mycommand As SqlCommand = myconnection.CreateCommand
                mycommand.CommandText = "delete from ongoing_trips where tripidtaking=" + tripIDtaking
                mycommand.ExecuteNonQuery()
            End Using
            myconnection.Close()
            Response.Redirect("myhistory.aspx")
        End If


    End If

End Sub

我不确定为什么在加载页面时发生此错误我收到此错误

0 个答案:

没有答案