Hello all -
Thank you in advance for any help you are able to provide.
I am populating a gridview from a stored procuedure. The returned data
is a name, phone number, email and guid of a contact in our database.
I also need to use the Edit and Delete funtions in the gridview.
Neither seems to be working as intended.
DeleteCommand=" delete from contactTable where Name = @ContactName and
Email = @ContactEmail and Phone = @ContactPhone and
(CAST(_Resource Guid AS varchar(36)) = @Guid)"
When I try to delete a contact, I get this error
System.Data.Sql Client.SqlExcep tion: Must declare the scalar variable
"@ContactNa me".
So, I added the Delete Parametres:
<DeleteParamete rs>
<asp:Paramete r Name="Contactam e" Type="string" />
<asp:Paramete r Name="ContactEm ail" Type="string" />
<asp:Paramete r Name="ContactPh one" Type="string" />
<asp:Paramete r Name="Guid" Type="string" />
</DeleteParameter s>
Now, when I try to delete, I get this:
System.InvalidC astException: Object must implement IConvertible.
The strange thing is, I am able to Update without having the
parameters specified using this
UpdateCommand=" update Altiris.dbo.Inv _Current_Allowe d_Contacts SET
Name = @ContactName, Email = @ContactEmail, Phone = @ContactPhone
WHERE (CAST(_Resource Guid AS varchar(36)) = @Guid)"
but once I add in a set of UpdateParamters similar to the parameters
indicated above I get the IConvertible error again.
I'm coding in VS Web Developer 2005. The full code for the gridview
control (with names changed to protect the innocent) is below. By
the way, I am showing the footer in advance of implementing an insert
function...
Thanks-
Danielle
<asp:GridView ID="gdContacts " runat="server"
AutoGenerateCol umns="False"
AutoGenerateEdi tButton="True"
AutoGenerateDel eteButton="True "
DataSourceID="s qlContactInfo"
DataKeyNames="G uid"
ShowFooter="Tru e">
<Columns>
<asp:TemplateFi eld HeaderText="Con tact Name"
SortExpression= "ContactNam e">
<EditItemTempla te>
<asp:TextBox ID="txtContactN ame"
runat="server" Text='<%# Bind("ContactNa me") %>'></asp:TextBox>
</EditItemTemplat e>
<ItemTemplate >
<asp:Label ID="lblContactN ame" runat="server"
Text='<%# Bind("ContactNa me") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateFie ld>
<asp:TemplateFi eld HeaderText="Con tact Email"
SortExpression= "ContactEma il">
<EditItemTempla te>
<asp:TextBox ID="txtContactE mail"
runat="server" Text='<%# Bind("ContactEm ail") %>'></asp:TextBox>
</EditItemTemplat e>
<ItemTemplate >
<asp:Label ID="lblContactE mail" runat="server"
Text='<%# Bind("ContactEm ail") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateFie ld>
<asp:TemplateFi eld HeaderText="Con tact Phone"
SortExpression= "ContactPho ne">
<EditItemTempla te>
<asp:TextBox ID="txtContactP hone"
runat="server" Text='<%# Bind("ContactPh one") %>'></asp:TextBox>
</EditItemTemplat e>
<ItemTemplate >
<asp:Label ID="lblContactP hone" runat="server"
Text='<%# Bind("ContactPh one") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateFie ld>
<asp:TemplateFi eld>
<FooterTemplate >
<asp:Button ID="btnInsert" runat="server"
CommandName="In sert" Text="Insert" />
</FooterTemplate>
<FooterStyle HorizontalAlign ="Center" />
</asp:TemplateFie ld>
<asp:TemplateFi eld HeaderText="Gui d"
SortExpression= "Guid" Visible="False" >
<EditItemTempla te>
<asp:TextBox ID="TextBox4" runat="server"
Text='<%# Bind("Guid") %>'></asp:TextBox>
</EditItemTemplat e>
<ItemTemplate >
<asp:Label ID="Label4" runat="server" Text='<
%# Bind("Guid") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateFie ld>
</Columns>
<HeaderStyle BackColor="Blac k" ForeColor="Whit e" />
<AlternatingRow Style BackColor="#FFE 16D" />
</asp:GridView>
<asp:SqlDataSou rce ID="sqlContactI nfo" runat="server"
ConnectionStrin g="<%$
ConnectionStrin gs:Altiris_Inci dentsConnection String %>"
SelectCommand=" usp_sp"
SelectCommandTy pe="StoredProce dure"
UpdateCommand=" update contactTable Contacts SET Name =
@ContactName, Email = @ContactEmail, Phone = @ContactPhone WHERE
(CAST(_Resource Guid AS varchar(36)) = @Guid)"
DeleteCommand=" delete from contactTable where Name =
@ContactName and Email = @ContactEmail and Phone = @ContactPhone and
(CAST(_Resource Guid AS varchar(36)) = @Guid)" >
<SelectParamete rs>
<asp:QueryStrin gParameter Name="agreement Guid"
QueryStringFiel d="agreementGui d" Type="String" />
</SelectParameter s>
<DeleteParamete rs>
<asp:Paramete r Name="Contactam e" Type="string" />
<asp:Paramete r Name="ContactEm ail" Type="string" />
<asp:Paramete r Name="ContactPh one" Type="string" />
<asp:Paramete r Name="Guid" Type="string" />
</DeleteParameter s>
</asp:SqlDataSour ce>
Thank you in advance for any help you are able to provide.
I am populating a gridview from a stored procuedure. The returned data
is a name, phone number, email and guid of a contact in our database.
I also need to use the Edit and Delete funtions in the gridview.
Neither seems to be working as intended.
DeleteCommand=" delete from contactTable where Name = @ContactName and
Email = @ContactEmail and Phone = @ContactPhone and
(CAST(_Resource Guid AS varchar(36)) = @Guid)"
When I try to delete a contact, I get this error
System.Data.Sql Client.SqlExcep tion: Must declare the scalar variable
"@ContactNa me".
So, I added the Delete Parametres:
<DeleteParamete rs>
<asp:Paramete r Name="Contactam e" Type="string" />
<asp:Paramete r Name="ContactEm ail" Type="string" />
<asp:Paramete r Name="ContactPh one" Type="string" />
<asp:Paramete r Name="Guid" Type="string" />
</DeleteParameter s>
Now, when I try to delete, I get this:
System.InvalidC astException: Object must implement IConvertible.
The strange thing is, I am able to Update without having the
parameters specified using this
UpdateCommand=" update Altiris.dbo.Inv _Current_Allowe d_Contacts SET
Name = @ContactName, Email = @ContactEmail, Phone = @ContactPhone
WHERE (CAST(_Resource Guid AS varchar(36)) = @Guid)"
but once I add in a set of UpdateParamters similar to the parameters
indicated above I get the IConvertible error again.
I'm coding in VS Web Developer 2005. The full code for the gridview
control (with names changed to protect the innocent) is below. By
the way, I am showing the footer in advance of implementing an insert
function...
Thanks-
Danielle
<asp:GridView ID="gdContacts " runat="server"
AutoGenerateCol umns="False"
AutoGenerateEdi tButton="True"
AutoGenerateDel eteButton="True "
DataSourceID="s qlContactInfo"
DataKeyNames="G uid"
ShowFooter="Tru e">
<Columns>
<asp:TemplateFi eld HeaderText="Con tact Name"
SortExpression= "ContactNam e">
<EditItemTempla te>
<asp:TextBox ID="txtContactN ame"
runat="server" Text='<%# Bind("ContactNa me") %>'></asp:TextBox>
</EditItemTemplat e>
<ItemTemplate >
<asp:Label ID="lblContactN ame" runat="server"
Text='<%# Bind("ContactNa me") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateFie ld>
<asp:TemplateFi eld HeaderText="Con tact Email"
SortExpression= "ContactEma il">
<EditItemTempla te>
<asp:TextBox ID="txtContactE mail"
runat="server" Text='<%# Bind("ContactEm ail") %>'></asp:TextBox>
</EditItemTemplat e>
<ItemTemplate >
<asp:Label ID="lblContactE mail" runat="server"
Text='<%# Bind("ContactEm ail") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateFie ld>
<asp:TemplateFi eld HeaderText="Con tact Phone"
SortExpression= "ContactPho ne">
<EditItemTempla te>
<asp:TextBox ID="txtContactP hone"
runat="server" Text='<%# Bind("ContactPh one") %>'></asp:TextBox>
</EditItemTemplat e>
<ItemTemplate >
<asp:Label ID="lblContactP hone" runat="server"
Text='<%# Bind("ContactPh one") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateFie ld>
<asp:TemplateFi eld>
<FooterTemplate >
<asp:Button ID="btnInsert" runat="server"
CommandName="In sert" Text="Insert" />
</FooterTemplate>
<FooterStyle HorizontalAlign ="Center" />
</asp:TemplateFie ld>
<asp:TemplateFi eld HeaderText="Gui d"
SortExpression= "Guid" Visible="False" >
<EditItemTempla te>
<asp:TextBox ID="TextBox4" runat="server"
Text='<%# Bind("Guid") %>'></asp:TextBox>
</EditItemTemplat e>
<ItemTemplate >
<asp:Label ID="Label4" runat="server" Text='<
%# Bind("Guid") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateFie ld>
</Columns>
<HeaderStyle BackColor="Blac k" ForeColor="Whit e" />
<AlternatingRow Style BackColor="#FFE 16D" />
</asp:GridView>
<asp:SqlDataSou rce ID="sqlContactI nfo" runat="server"
ConnectionStrin g="<%$
ConnectionStrin gs:Altiris_Inci dentsConnection String %>"
SelectCommand=" usp_sp"
SelectCommandTy pe="StoredProce dure"
UpdateCommand=" update contactTable Contacts SET Name =
@ContactName, Email = @ContactEmail, Phone = @ContactPhone WHERE
(CAST(_Resource Guid AS varchar(36)) = @Guid)"
DeleteCommand=" delete from contactTable where Name =
@ContactName and Email = @ContactEmail and Phone = @ContactPhone and
(CAST(_Resource Guid AS varchar(36)) = @Guid)" >
<SelectParamete rs>
<asp:QueryStrin gParameter Name="agreement Guid"
QueryStringFiel d="agreementGui d" Type="String" />
</SelectParameter s>
<DeleteParamete rs>
<asp:Paramete r Name="Contactam e" Type="string" />
<asp:Paramete r Name="ContactEm ail" Type="string" />
<asp:Paramete r Name="ContactPh one" Type="string" />
<asp:Paramete r Name="Guid" Type="string" />
</DeleteParameter s>
</asp:SqlDataSour ce>
Comment