Delete record from table that has related table - ms-access

I am working in MS Access and I getting "cannot delete from specified tables" errors.
My tables are:
Orders
OrderDetails
Products
OrderView
OrderView is a query table with data is from OrderDetails and Products tables respectively.
I am trying to delete records from OrderDetails where the productId matches my productId in the a gridview.
My sql statement is:
DELETE * FROM OrderDetails WHERE productId=#productId
I am getting #productId from the grid view
This is my grid view markup:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataSourceID="row3" BackColor="White" BorderColor="#CCCCCC"
BorderStyle="None" BorderWidth="1px" CellPadding="4" ForeColor="Black"
GridLines="Horizontal"
DataKeyNames="oProductId"
width="100%"
>
<Columns>
<asp:BoundField DataField="oProductId" HeaderText="Product Id"
SortExpression="oProductId" />
<asp:BoundField DataField="pProductName" HeaderText="Product Name"
SortExpression="pProductName" />
<asp:BoundField DataField="oQty" HeaderText="Quantity"
SortExpression="oQty" />
<asp:BoundField DataField="oPrice" HeaderText="Price" SortExpression="oPrice"
DataFormatString="{0:c}" />
<asp:BoundField DataField="oAmt" HeaderText="Amount"
SortExpression="oAmt" ReadOnly="True" DataFormatString="{0:c}" />
<asp:TemplateField HeaderText="Action">
<ItemTemplate>
<asp:LinkButton ID="btnDelete" Text="Delete" runat="server" CommandName="Delete" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="#CCCC99" ForeColor="Black" />
<HeaderStyle BackColor="#333333" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="White" ForeColor="Black" HorizontalAlign="Right" />
<SelectedRowStyle BackColor="#CC3333" Font-Bold="True" ForeColor="White" />
<SortedAscendingCellStyle BackColor="#F7F7F7" />
<SortedAscendingHeaderStyle BackColor="#4B4B4B" />
<SortedDescendingCellStyle BackColor="#E5E5E5" />
<SortedDescendingHeaderStyle BackColor="#242121" />

How many records are in that table? How many records are you trying to delete?
I run into the overflow error when I try to delete more than 30,000 records out of a table containing 1 million + records. This seems to be an Access limitation. Access cannot handle enough memory to hold all records in memory and do a search and delete while keeping the deleted data for the purpose of rolling back in event of error. That's my best guess.
I have tackled this issue using 2 strategies: 1) Do not insert any records into a large table unless absolutely sure I need them inserted right now. Use a temp table or global var array to temporarily store values. 2) Delete in small chunks. E.G. DELETE ... WHERE ID BETWEEN 20000 AND 25000. Make sure the column you name in the WHERE clause is an Indexed column. I include such a statement in a loop, incrementing the 2 vals in the BETWEEN phrase.

Related

How To Display CKEditor Data In Stimulsoft? and In WebForm Grid View?

How To Display CKEditor Data In Stimulsoft? and In WebForm Grid View ?
I Use CkEditor to Save My Data In SQL then Data Saved as HTML Tags In Database
When I want to Display Data In StimulSoft
My data Show As HTML Tag . but I want to Display with out Html Tags.
Well, for the most part, you can directly display such content on a web page.
In most cases, even a simple label dropped onto the form will correctly render that column of data.
Say we have a simple GridView like this:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataKeyNames="ID"
CssClass="table table-hover" Width="50%" GridLines="None"
ShowHeaderWhenEmpty="true">
<Columns>
<asp:BoundField DataField="FirstName" HeaderText="FirstName" />
<asp:BoundField DataField="LastName" HeaderText="LastName" />
<asp:BoundField DataField="City" HeaderText="City" />
<asp:BoundField DataField="HotelName" HeaderText="HotelName" />
<asp:BoundField DataField="Description" HeaderText="Description" />
<asp:TemplateField HeaderText="Info">
<ItemTemplate>
<asp:Label ID="lblMarkUp" runat="server" width="340px"
Text='<%# Eval("ImageInfo") %>' >
</asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:Button ID="cmdEdit" runat="server" Text="Edit" CssClass="btn myshadow"
OnClick="cmdEdit_Click" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
and out code beind to load is this:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
LoadGrid()
End If
End Sub
Sub LoadGrid()
Dim strSQL As String = "SELECT * FROM tblHotelsP ORDER BY HotelName"
GridView1.DataSource = Myrst(strSQL)
GridView1.DataBind()
End Sub
So, all we did was shove a data table right into the grid.
However, note that ONE column we have. I don't have ckedit installed, but I do have the ajaxtoolkit HTML editor. The results will be the same. We "save" that one column right into the database.
So, in most cases, any markup, and even ctrl-v to paste in a picture will work.
The results of the above grid are thus this:
A text box will not work, but a label will as per above.
You can also say use a content placeholder or whatever. However, I find just a simple label control works rather well in most cases (as the above example grid using a label shows)

Use different data forms inside default grid view in asp.net

I have the above grid view where I am using the default one provided by Visual Studio. What I am doing is, via the server properties dragging the table and the VS creates the above for me.
However, I want my category 1 and category 2 and category 3 be dropdown lists.
Is there any way to change the default behavior of the grid view?
Use Template Field in the source code inside the grid.
It will look like
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" OnRowDataBound="OnRowDataBound">
<Columns>
<asp:BoundField HeaderText="id" DataField="id" />
<asp:BoundField HeaderText="Name" DataField="name" />
<asp:TemplateField HeaderText = "category1">
<ItemTemplate>
<asp:Label ID="lblcategory1" runat="server" Text='<%# Eval("category1") %>' Visible = "false" />
<asp:DropDownList ID="ddlcategory1" runat="server">
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
and so on.

apply a condition in html based on a boundfield

I have a gridview and a command field that is a link to a page. How can I replace the link with just text based upon an field in the record?
Here is the code:
<asp:CommandField SelectText="View" ShowSelectButton="True">
<ItemStyle Width="50px" />
</asp:CommandField>
So I want to replace the CommandField with "N/A" for a record that meets a criteria of Date<2015. Where Date is a field in the record.
Thank you.
This is task worth a custom template field. I'd suggest to have both controls in the template, and show either one or the other based on your condition. Something like this:
<TemplateField>
<ItemTemplate>
<asp:Literal Text="N/A" runat="server" Visible='<%# ((DateTime)Eval("FieldName")).Year < 2015 %>'>
<asp:Button Text="View" CommandName="Select" runat="server" Visible='<%# (int)Eval("FieldName") >= 2015 %>'>
</ItemTemplate>
</TemplateField>
So as you can see the literal with N/A text and the button basically alternate visibility based on the condition.

What's the difference in asp tags if we use <asp:BoundField /> or <asp:BoundField> and </asp:BoundField>?

I'm starting to understand ASP code through a complete project written by others. In the aspx file, there is code like
<asp:BoundField DataField="Location" HeaderStyle-HorizontalAlign="Center"
HeaderText="Location" SortExpression="Location">
<HeaderStyle HorizontalAlign="Center" />
</asp:BoundField>
. but if I put
<asp:BoundField DataField="Lcation" HeaderStyle-HorizontalAlign="Center" HeaderText="Location" SortExpression="Location" />
, it's also works. I'm wondering about if there is difference between those ending tags with/without the name of beginning. Thanks!
That's called a self-closing tag.
They're identical.

GridView Centering Issues

How can I center the text of the rows of an <asp:GridView /> that gets populated at run-time?
I have tried RowStyle-HorizontalAlign="Center" and similar things that I have found in this site to no avail.
Similarly, I cannot center a GridView inside a div—that is, <div><asp:GridView /></div>—to save my life.
Am I using a bunch of deprecated functions or what? Also, Chrome is my default browser.
I am aware that a thousand questions in the gist of mine have been asked before, but all that I have tried are either years old or are not working.
Thanks in advance!
Are you using bound columns or autogenerated? If you're binding them in your markup, something like this should work fine (this is an actual example from something of mine):
<asp:TemplateField HeaderText="External Id" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center" FooterStyle-HorizontalAlign="Center">
<EditItemTemplate>
<asp:TextBox ID="txtExternalId" runat="server" Text='<%#Bind("ExternalId")%>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtNewExternalId" runat="server" Width="100%" />
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="lblExternalId" runat="server" Text='<%#Bind("ExternalId")%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>