当我尝试使用GridView页脚模板将数据插入oracle数据库中的数据插入到oracle数据库中时,在插入查询中出现此“ ORA-01008:未绑定所有变量”错误,我在服务器上测试了查询而且效果很好,但是当我尝试运行该应用并使用添加按钮执行查询时,它会显示错误
**网格视图代码正在使用模板字段,因此我可以编辑页脚模板的网格视图**
<asp:GridView ID="gvmb" runat="server" AutoGenerateColumns="False" BackColor="#DEBA84" BorderColor="#DEBA84" BorderStyle="None" BorderWidth="1px" CellPadding="3" CellSpacing="2" Width="60%" style="margin-left: 350px" Height="226px" ShowFooter="True" OnRowCommand="gvmb_RowCommand" DataKeyNames="member_id" ShowHeaderWhenEmpty="True">
<FooterStyle BackColor="#F7DFB5" ForeColor="#8C4510" />
<HeaderStyle BackColor="#A55129" Font-Bold="True" ForeColor="White" />
<PagerStyle ForeColor="#8C4510" HorizontalAlign="Center" />
<RowStyle BackColor="#FFF7E7" ForeColor="#8C4510" />
<SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="White" />
<SortedAscendingCellStyle BackColor="#FFF1D4" />
<SortedAscendingHeaderStyle BackColor="#B95C30" />
<SortedDescendingCellStyle BackColor="#F1E5CE" />
<SortedDescendingHeaderStyle BackColor="#93451F" />
<Columns>
<asp:TemplateField HeaderText="id">
<ItemTemplate>
<asp:Label text='<%# Eval("member_id") %>' runat="server"></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="member" text='<%# Eval("member_id") %>' runat="server">
</asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="member_idfooter" runat="server">
</asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Name">
<ItemTemplate>
<asp:Label text='<%# Eval("user_name") %>' runat="server"></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="uname" text='<%# Eval("user_name") %>' runat="server">
</asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="user_namefooter" runat="server">
</asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="address">
<ItemTemplate>
<asp:Label text='<%# Eval("address") %>' runat="server"></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="addres" text='<%# Eval("address") %>' runat="server">
</asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="addressfooter" runat="server">
</asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Email">
<ItemTemplate>
<asp:Label text='<%# Eval("email_address") %>' runat="server"></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="email" text='<%# Eval("email_address") %>' runat="server">
</asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="email_addressfooter" runat="server">
</asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="password">
<ItemTemplate>
<asp:Label text='<%# Eval("password") %>' runat="server"></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="pass" text='<%# Eval("password") %>' runat="server">
</asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="passwordfooter" runat="server">
</asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="mobile number">
<ItemTemplate>
<asp:Label text='<%# Eval("mob_number") %>' runat="server"></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="mob" text='<%# Eval("mob_number") %>' runat="server">
</asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="mob_numberfooter" runat="server">
</asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="edit" runat="server" CommandName="edit" ToolTip="Edit">Edit</asp:LinkButton>
<asp:LinkButton ID="delete" runat="server" CommandName="delete" ToolTip="Delete">Delete</asp:LinkButton>
</ItemTemplate>
<FooterTemplate>
<asp:LinkButton ID="add" runat="server" CommandName="add" ToolTip="add">add</asp:LinkButton>
</FooterTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<br />
<asp:Label Text="" ID="lblsuccess" runat="server" ForeColor="Green"></asp:Label>
<br />
<asp:Label Text="" ID="lblerror" runat="server" ForeColor="red"></asp:Label>
</div>
包含插入事件的C#代码我在add.ExcuteNonQuery()方法中收到错误
if (e.CommandName.Equals("add"))
{
coon.Open();
string query = "INSERT INTO members (member_id, user_name,address ,mob_number,email_address,password ) VALUES (:member_id, :user_name,:address ,:mob_number,:email_address,:password)";
OleDbCommand add = new OleDbCommand(query, coon);
add.Parameters.AddWithValue(":member_id", (gvmb.FooterRow.FindControl("member_idfooter") as TextBox).Text.Trim());
add.Parameters.AddWithValue(":user_name", (gvmb.FooterRow.FindControl("user_namefooter") as TextBox).Text.Trim());
add.Parameters.AddWithValue(":address", (gvmb.FooterRow.FindControl("addressfooter") as TextBox).Text.Trim());
add.Parameters.AddWithValue(":mob_number", (gvmb.FooterRow.FindControl("mob_numberfooter") as TextBox).Text.Trim());
add.Parameters.AddWithValue(":email_address", (gvmb.FooterRow.FindControl("email_addressfooter") as TextBox).Text.Trim());
add.Parameters.AddWithValue(":password", (gvmb.FooterRow.FindControl("passwordfooter") as TextBox).Text.Trim());
add.ExecuteNonQuery();
fillmembers();
lblsuccess.Text = "New Recored Added";
lblerror.Text = "";
coon.Close();
}
答案 0 :(得分:0)
如果您可以改为使用OracleCommand,则可以使用特定于Oracle的OracleParamater来使其工作。
cmd.Parameters.Add(new OracleParameter("client", client));
取决于您拥有的命名空间是Oracle.DataAccess.Client还是System.Data.OracleClient,您可以使用AddWithValue版本。
答案 1 :(得分:0)
解决了,我只是将查询中的:参数更改为?我猜它起作用了,参数顺序
插入INTO成员(member_id,用户名,地址,mob_number,电子邮件地址,密码)VALUES(?,?,?,?,?,?)