Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Input string error in "update statment"

Status
Not open for further replies.

toddw607

Programmer
Apr 2, 2007
55
US
Hello,
I have a problem with updating a datagrid. I have a function for a save button but when I press it it gives me an error saying that my update statement is incorrect. Here is the code to my update statement:
Private Sub doSave(ByVal sender As Object, ByVal e As System.EventArgs)

Dim myCommand As SqlCommand
Dim dstCopy As New DataSet
Dim strQuery As String

objConnection = New SqlConnection("server=SQLSERVER;database=upsizedCandidate;Integrated Security=True;")
objConnection.Open()
Dim dgItem As DataGridItem
For Each dgItem In myInfo.Items
Dim txtCAGE As TextBox = _
CType(dgItem.Cells(0).FindControl("txtCAGE"), TextBox)

Dim txtName As TextBox = _
CType(dgItem.Cells(1).FindControl("txtName"), TextBox)

Dim txtStreet As TextBox = _
CType(dgItem.Cells(2).FindControl("txtStreet"), TextBox)

Dim txtCity As TextBox = _
CType(dgItem.Cells(3).FindControl("txtCity"), TextBox)

Dim txtState As TextBox = _
CType(dgItem.Cells(4).FindControl("txtState"), TextBox)

Dim txtNation As TextBox = _
CType(dgItem.Cells(5).FindControl("txtNation"), TextBox)

Dim txtPostal As TextBox = _
CType(dgItem.Cells(6).FindControl("txtPostal"), TextBox)

Dim txtPhone As TextBox = _
CType(dgItem.Cells(7).FindControl("txtPhone"), TextBox)



strQuery = "INSERT INTO XH (CAGE, Name, Street, City, State, Nation, Postal, Phone) VALUES('" & +txtCAGE.Text + _
+ ", " + txtName.Text + ", " + txtStreet.Text + ", " + txtCity.Text + ", " + txtState.Text + ", " + & _
+txtNation.Text + ", " + txtPostal.Text + ", " + txtPhone.Text + ")"

myCommand = New SqlCommand(strQuery, objConnection)
myCommand.ExecuteNonQuery()

Next
objConnection.Close()
ShowDataGrid()
End Sub


and here is my datagrid:

<form id="Form1" runat="server">
<H3 id="H3_1">Editing XH from SQL Server </H3>

<asp:DataGrid id="myInfo"

OnItemCommand="doInsert"
OnDeleteCommand="DBDelDataGrid_Delete"
ShowFooter="True"
runat="server"
DataKeyField="id"
AutoGenerateColumns="False" CellPadding="4"
BackColor=" #C6DEFF"
EditItemStyle-BackColor="#eeeeee"
HeaderStyle-BackColor="Black"
HeaderStyle-ForeColor="Blue"
HeaderStyle-HorizontalAlign="Center"
HeaderStyle-Font-Bold="True">
<Columns>
<asp:TemplateColumn HeaderText="CAGE">
<FooterTemplate>
<asp:TextBox ID="add_CAGE" Columns="7" Runat="Server" />
</FooterTemplate>

<ItemTemplate>
<asp:TextBox MaxLength="50" runat="server" ID="txtCAGE" cssclass="TEXTBOX_MEDIUM_DG1" Text='<%# Container.DataItem("CAGE") %>' />
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="CAGE" Columns="7"
Text='<%# Container.DataItem("CAGE") %>' Runat="server" />
</EditItemTemplate>
</asp:TemplateColumn>

<asp:TemplateColumn HeaderText="Name">
<FooterTemplate>
<asp:TextBox ID="add_Name" Columns="7" Runat="Server" />
</FooterTemplate>
<ItemTemplate>
<asp:TextBox MaxLength="50" runat="server" ID="txtName" cssclass="TEXTBOX_MEDIUM_DG1" Text='<%# Container.DataItem("Name") %>' />
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="Name" Columns="7"
Text='<%# Container.DataItem("Name") %>' Runat="server" />
</EditItemTemplate>
</asp:TemplateColumn>

<asp:TemplateColumn HeaderText="Street">
<FooterTemplate>
<asp:TextBox ID="add_Street" Columns="7" Runat="Server" />
</FooterTemplate>
<ItemTemplate>
<asp:TextBox MaxLength="50" runat="server" ID="txtStreet" cssclass="TEXTBOX_MEDIUM_DG1" Text='<%# Container.DataItem("Street") %>' />
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="Street" Columns="7"
Text='<%# Container.DataItem("Street") %>' Runat="server" />
</EditItemTemplate>
</asp:TemplateColumn>

<asp:TemplateColumn HeaderText="City">
<FooterTemplate>
<asp:TextBox ID="add_City" Columns="7" Runat="Server" />
</FooterTemplate>
<ItemTemplate>
<asp:TextBox MaxLength="50" runat="server" ID="txtCity" cssclass="TEXTBOX_MEDIUM_DG1" Text='<%# Container.DataItem("City") %>' />
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="City" Columns="7"
Text='<%# Container.DataItem("City") %>' Runat="server" />
</EditItemTemplate>
</asp:TemplateColumn>

<asp:TemplateColumn HeaderText="State">
<FooterTemplate>
<asp:TextBox ID="add_State" Columns="7" Runat="Server" />
</FooterTemplate>
<ItemTemplate>
<asp:TextBox MaxLength="50" runat="server" ID="txtState" cssclass="TEXTBOX_MEDIUM_DG1" Text='<%# Container.DataItem("State") %>' />
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="State" Columns="7"
Text='<%# Container.DataItem("State") %>' Runat="server" />
</EditItemTemplate>
</asp:TemplateColumn>

<asp:TemplateColumn HeaderText="Nation">
<FooterTemplate>
<asp:TextBox ID="add_Nation" Columns="7" Runat="Server" />
</FooterTemplate>
<ItemTemplate>
<asp:TextBox MaxLength="50" runat="server" ID="txtNation" cssclass="TEXTBOX_MEDIUM_DG1" Text='<%# Container.DataItem("Nation") %>' />
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="Nation" Columns="7"
Text='<%# Container.DataItem("Nation") %>' Runat="server" />
</EditItemTemplate>
</asp:TemplateColumn>

<asp:TemplateColumn HeaderText="Postal">
<FooterTemplate>
<asp:TextBox ID="add_Postal" Columns="7" Runat="Server" />
</FooterTemplate>
<ItemTemplate>
<asp:TextBox MaxLength="50" runat="server" ID="txtPostal" cssclass="TEXTBOX_MEDIUM_DG1" Text='<%# Container.DataItem("Postal") %>' />
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="Postal" Columns="7"
Text='<%# Container.DataItem("Postal") %>' Runat="server" />
</EditItemTemplate>
</asp:TemplateColumn>

<asp:TemplateColumn HeaderText="Phone">
<FooterTemplate>
<asp:TextBox ID="add_Phone" Columns="7" Runat="Server" />
</FooterTemplate>
<ItemTemplate>
<asp:TextBox MaxLength="50" runat="server" ID="txtPhone" cssclass="TEXTBOX_MEDIUM_DG1" Text='<%# Container.DataItem("Phone") %>' />
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="Phone" Columns="7"
Text='<%# Container.DataItem("Phone") %>' Runat="server" />
</EditItemTemplate>
</asp:TemplateColumn>

<asp:TemplateColumn HeaderText="Insert">
<FooterTemplate>
<asp:Button CommandName="Insert" Text="Add" ID="btnAdd" Runat="server" />
</FooterTemplate>
<ItemTemplate>
<asp:Button CommandName="Delete" Text="Delete" ID="btnDel" Runat="server" />
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Save">
<FooterTemplate>
<asp:Button CommandName="Save" Text="Save" ID="btnSave" OnClick="doSave" runat="server" />
</FooterTemplate>
</asp:TemplateColumn>

</Columns>
</asp:DataGrid>



</form>
</body>
</html>

Can someone please tell me what is the problem. I've been working on this for almost a week and I'm not sure which syntax to use. Thank you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top