FormView Issue
-
I am creating a golf Application to keep track of my stats and I am using a formview. Is there a better way to do this... Private Sub GetPutts() Dim txtPuttOne As TextBox = Me.FormView1.FindControl("txtPuttsHoleOne") Dim intPuttOne As Integer = CInt(txtPuttOne.Text) Dim txtPuttTwo As TextBox = Me.FormView1.FindControl("txtPuttsHoleTwo") Dim intPutttwo As Integer = CInt(txtPuttTwo.Text) Dim txtPuttThree As TextBox = Me.FormView1.FindControl("txtPuttsHoleThree") Dim intPuttThree As Integer = CInt(txtPuttThree.Text) Dim txtPuttFour As TextBox = Me.FormView1.FindControl("txtPuttsHoleFour") Dim intPuttFour As Integer = CInt(txtPuttFour.Text) Dim txtPuttFive As TextBox = Me.FormView1.FindControl("txtPuttsHoleFive") ***all the way to Hole 18 Try dsPutts.InsertCommand = "INSERT INTO [dbo].[Putt_Info] " dsPutts.InsertCommand += "([CourseId] ,[UserId],[ScoreID],[PuttsHoleOne]," dsPutts.InsertCommand += "[PuttsHoleTwo],[PuttsHoleThree],[PuttsHoleFour]," dsPutts.InsertCommand += "[PuttsHoleFive],[PuttsHoleSix] ,[PuttsHoleSeven]," dsPutts.InsertCommand += "[PuttsHoleEight],[PuttsHoleNine],[PuttsHoleTen]," dsPutts.InsertCommand += "[PuttsHoleEleven],[PuttsHoleTwelve],[PuttsHoleThirteen]," dsPutts.InsertCommand += "[PuttsHoleFourteen],[PuttsHoleFifteen],[PuttsHoleSixteen]," dsPutts.InsertCommand += "[PuttsHoleSeventeen] ,[PuttsHoleEighteen])" dsPutts.InsertCommand += "VALUES('" & courseID & "', '" & Session("UserName") & "', '" dsPutts.InsertCommand += Session("ScoreID") & "'," & intPuttOne & "," & intPutttwo & "," & intPuttThree & "," & intPuttFour & "," & intPuttFive & "," & intPuttSix & "," & intPuttSeven dsPutts.InsertCommand += "," & intPuttEight & "," & intPuttNine & "," & intPuttTen & "," & intPuttEleven & "," & intPuttTwelve & "," & intPuttThirteen dsPutts.InsertCommand += "," & intPuttFourteen & "," & intPuttFifteen & "," & intPuttSixteen & "," & intPuttSevenTeen & "," & intPuttEighteen & ")" dsPutts.InsertCommandType = SqlDataSourceCommandType.Text dsPutts.Insert() Catch ex As Exception Response.Write(ex) End Try End Sub I basically just want to grab the text the user enters in each of the controls and then insert it into the database. Thanks in advance
-
I am creating a golf Application to keep track of my stats and I am using a formview. Is there a better way to do this... Private Sub GetPutts() Dim txtPuttOne As TextBox = Me.FormView1.FindControl("txtPuttsHoleOne") Dim intPuttOne As Integer = CInt(txtPuttOne.Text) Dim txtPuttTwo As TextBox = Me.FormView1.FindControl("txtPuttsHoleTwo") Dim intPutttwo As Integer = CInt(txtPuttTwo.Text) Dim txtPuttThree As TextBox = Me.FormView1.FindControl("txtPuttsHoleThree") Dim intPuttThree As Integer = CInt(txtPuttThree.Text) Dim txtPuttFour As TextBox = Me.FormView1.FindControl("txtPuttsHoleFour") Dim intPuttFour As Integer = CInt(txtPuttFour.Text) Dim txtPuttFive As TextBox = Me.FormView1.FindControl("txtPuttsHoleFive") ***all the way to Hole 18 Try dsPutts.InsertCommand = "INSERT INTO [dbo].[Putt_Info] " dsPutts.InsertCommand += "([CourseId] ,[UserId],[ScoreID],[PuttsHoleOne]," dsPutts.InsertCommand += "[PuttsHoleTwo],[PuttsHoleThree],[PuttsHoleFour]," dsPutts.InsertCommand += "[PuttsHoleFive],[PuttsHoleSix] ,[PuttsHoleSeven]," dsPutts.InsertCommand += "[PuttsHoleEight],[PuttsHoleNine],[PuttsHoleTen]," dsPutts.InsertCommand += "[PuttsHoleEleven],[PuttsHoleTwelve],[PuttsHoleThirteen]," dsPutts.InsertCommand += "[PuttsHoleFourteen],[PuttsHoleFifteen],[PuttsHoleSixteen]," dsPutts.InsertCommand += "[PuttsHoleSeventeen] ,[PuttsHoleEighteen])" dsPutts.InsertCommand += "VALUES('" & courseID & "', '" & Session("UserName") & "', '" dsPutts.InsertCommand += Session("ScoreID") & "'," & intPuttOne & "," & intPutttwo & "," & intPuttThree & "," & intPuttFour & "," & intPuttFive & "," & intPuttSix & "," & intPuttSeven dsPutts.InsertCommand += "," & intPuttEight & "," & intPuttNine & "," & intPuttTen & "," & intPuttEleven & "," & intPuttTwelve & "," & intPuttThirteen dsPutts.InsertCommand += "," & intPuttFourteen & "," & intPuttFifteen & "," & intPuttSixteen & "," & intPuttSevenTeen & "," & intPuttEighteen & ")" dsPutts.InsertCommandType = SqlDataSourceCommandType.Text dsPutts.Insert() Catch ex As Exception Response.Write(ex) End Try End Sub I basically just want to grab the text the user enters in each of the controls and then insert it into the database. Thanks in advance
well, if u r using VS.NET 2005 u can do it in a very simple way by using an SqlDataSource object. You can configure the SqlDataSource object by appropriately selecting the server name, the database and the table u want to add the data. Then it automatically generates the SELECT,INSERT,UPDATE,DELETE statements or u can use ur own stored Procedures to do them. then drag n drop a formview on to the application and set it's datasource to SqlDataSource. e.g: FormView1.DataSource = SqlDataSource1; FormView1.DataBind();
-
well, if u r using VS.NET 2005 u can do it in a very simple way by using an SqlDataSource object. You can configure the SqlDataSource object by appropriately selecting the server name, the database and the table u want to add the data. Then it automatically generates the SELECT,INSERT,UPDATE,DELETE statements or u can use ur own stored Procedures to do them. then drag n drop a formview on to the application and set it's datasource to SqlDataSource. e.g: FormView1.DataSource = SqlDataSource1; FormView1.DataBind();