Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > You cannot add or change a record because a related record is required in table 'lok"

Reply
Thread Tools

You cannot add or change a record because a related record is required in table 'lok"

 
 
André
Guest
Posts: n/a
 
      06-25-2006
Hi,

Still the same (unsolved problem), but other error now.
I have a detailsview for inserting data, and a dropdownlist which
selectedValue must be used to fill one of the field of the detailsview.
Table 'pc' is related to table 'lok'.

I tried a lot of things, but still without succes. Here are the two methods
i tried with two different errors. It works only when i introduce directly a
value in "DefaultValue" (see below)

Thanks for any help
André


1) first method:
asp:SqlDataSource ID="SqlDataSource1" runat="server" ....
....
InsertCommand="INSERT INTO [pc] ([na], [ty], [lok]) VALUES (?, ?, @lok)"
OldValuesParameterFormatString="original_{0}"
ProviderName="System.Data.OleDb"
<InsertParameters>
<asparameter Name="na" Type="String" />
<asparameter Name="ty" Type="String" />
</InsertParameters>
.....
Code-behind:
Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object,
ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
lok = DropDownList1.SelectedValue
SqlDataSource1.InsertParameters.Add("lok", lokl)
End Sub

This gives: No value given for one or more required parameters
----------------------------------------------------------------------------
-------------------------
2) second method
asp:SqlDataSource ID="SqlDataSource1" runat="server" ....
....
InsertCommand="INSERT INTO [pc] ([na], [ty], [lok]) VALUES (?, ?, @lok)"
OldValuesParameterFormatString="original_{0}"
ProviderName="System.Data.OleDb"
<InsertParameters>
<asparameter Name="na" Type="String" />
<asparameter Name="ty" Type="String" />
<asparameter Name="lok" Type="String" DefaultValue="<%=lok %>" />
</InsertParameters>
....

Code-behind:
Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object,
ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
lok = DropDownList1.SelectedValue
End Sub

This gives: You cannot add or change a record because a related record is
required in table 'lokl'
which means in fact that the value of the parameter is not passed!

It works when i give directly a value: <asparameter Name="lok"
Type="String" DefaultValue="1-45" />






 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Would you buy a P&S because Ashton Kutcher says you should? Rich Digital Photography 66 06-30-2010 03:11 AM
Cannot delete a file the process cannot access the file because it is being used by another process ASp.net 2 ary ASP .Net 2 11-29-2006 04:30 AM
Cannot delete a file the process cannot access the file because it is being used by another process ASp.net 2 ary ASP .Net 0 11-28-2006 09:13 AM
You cannot add or change a record because a related record is required in table 'lok" André ASP .Net 0 06-25-2006 01:30 PM
Cannot Copy Assembly <MyAssembly> The Process Cannot Access The File Because It Is Being Used By Another Process Ram ASP .Net 2 06-30-2005 11:30 AM



Advertisments