|
Hello
I am getting the following error:
System.Data.OleDb.OleDbException: Operation must use an updateable query.
when I type in a valid user's email (he exists in the Access mdb) on this page:
forgotten password[^]
I have read a couple of articles on this question, including this one:
Solve Operation Must Use an Updateable Query Error in Access[^]
and have set my permissions accordingly. The folder that houses my Access database, App_Data, has the following permissions: SYSTEM, Steve, and Administrators have full permissions, and Home Users have all permissions apart from Full Control.
[^]
After compiling my project, that folder is now on the server of my Web hosting service and these are the file permissions of App_Data on the server:
[^]
However, I am still getting the same error. Do I need to do anything in the Control Panel of the server, too (I have a Web hosting service) or is what I have already enough>
Thank you.
|
|
|
|
|
When you use an Access database, the code needs to be able to create, modify and delete files in the directory containing the .mdb file.
In ASP.NET, the server-side code does not run as a normal user. Depending on the settings for your AppPool, it will either run as a specific user for that pool, or as the Network Service account.
On your local machine, you need to give the IIS_IUSRS group "modify" access to the folder. This group contains all of the AppPool-specific users created by IIS.
You'll need to contact your hosting company to find out what permissions you need to apply there.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I want to implement Crud operation with generic repository ,unit of work, repository and service layer. I did all the layers but i don't know how to implement it in the controller.Please Help!!
|
|
|
|
|
This reads like the start of a bad joke.
Seriously, though, show us what your issue is (such as how you have your UoW/Repository defined) or you'll never get help with it.
And if I might humbly suggest: if you're not prepared to do query your DAL from your business layer, please don't over-reach on your architectural concerns. Reel it back until it clicks.
"There are three kinds of lies: lies, damned lies and statistics."
- Benjamin Disraeli
|
|
|
|
|
You wrote a layered generic repo that supports UoW...but you don't know how to call your code from a controller? I don't understand how you can develop such a thing yet don't know how to call one class from another?
|
|
|
|
|
Hi guys, I´m new to ASP.NET Core and EF Core and I have the following problem:
I have two related objects, Goals and Months, Goals got the foreign key of Months, and when I try to save the data of goals I got a foreign key error because the value of MonthId is 0, but when I create the select in the HTML I got correct code value.
Description of the error:
SqlException: The INSERT statement conflicted with the FOREIGN KEY constraint FK_Goals_MonthId;. The conflict occurred in database Portal_RNT, table dbo.Months , column MonthId;.
The statement has been terminated.
Here is the code:
HTML
@model ProjectName.Models.Goals
<div>
<form asp-controller="Goals" asp-action="Create">
Other form elements
<select name="months" asp-for="MonthId" class="form-control" asp-items="ViewBag.Months">
</select>
<input type="submit" value="Save" class="btn btn-primary" />
</form>
</div>
Goals Model
public class Goals
{
[Display(Name = "Code")]
public Int32 GoalId { get; set; }
public String GoalName{ get; set; }
public Months Month{ get; set; }
public Int32 MonthId{ get; set; }
....
Other properties
}
Month Model
public class Months
{
[Key]
[Display(Name = "Code")]
public Int32 MonthId { get; set; }
[Display(Name = "Designation")]
public String Designation{ get; set; }
}
Goals Controller
public IActionResult Create(Goals goal)
{
if (ModelState.IsValid)
{
_context.Goals.Add(goal);
_context.SaveChanges();
}
return View("~/../Create.cshtml");
}
Best Regards
|
|
|
|
|
Hi all,
I'm working on reducing the amount of calls to the DB in the applications at our company. One issue that I'm seeing is that the same data is being used by the MVC Controller and the AngularJS controller and an individual call is being made to the DB for each.
I'd like to find a clean way to pass a model into the AngularJS controller when it loads. What suggestions would you have as far as setting this up?
Thanks!
|
|
|
|
|
The best way I've found to conceptualize a SPA is that it's 2 completely separate applications: one for UX/business and the other for data access/projections.
From that standpoint, the optimal backend is a service, which in the .NET world usually means WebAPI for data projected through HTML templates as managed by Angular. You shouldn't use your MVC controllers for any populated views; just get your templates with it (if you absolutely have to have the MVC controllers at all) and JsonResult responses for data access.
"There are three kinds of lies: lies, damned lies and statistics."
- Benjamin Disraeli
|
|
|
|
|
So that is actually how it is currently set up. In this specific case though, I have a page that generates and displays a chart using a .NET tool called SpreadsheetGear. The appearance of the chart is dependent on settings the user has submitted (which we store in the DB). So the Action that generates this chart obviously needs access to that data. However, this page has a modal window that you can open that has an interface where the user can change the settings (AngularJS). We need to prepopulate this with the current settings, so the Javascript needs the same set of data as the Action that generated the chart.
Hopefully I did a good enough job describing the setup. This seems like a decent candidate for a case where an Action and the JS need access to the same data. How would you recommend dealing with this? I'm hoping to not have to execute the same query on the DB twice.
|
|
|
|
|
No, that makes perfect sense.
From my standpoint, I'd usually try and do that job on the JS side because I strictly try and keep UX on the JS side.
There is another option, you could pipeline your responses so that you have a standard response object that is parsed out by Angular. This is not fundamentally dissimilar to how I usually structure services that are meant for consumption by Angular, here's a sloppy example:
public class UXResponse
{
public Dictionary<string,string> Templates{ get; set; }
public object[] Models { get; set; }
}
public ActionResult Chart(int stuff)
{
var queriedItems = context.Stuff.Where(x => x.thing == stuff).ToArray();
var chart = ChartProvider.DoSomethingToGenerate(queriedItems);
...
var response = new UXResponse();
response.Templates.Add("controls", chart.ToHTMLResponseOrWhatever());
response.Models = queriedItems;
return response;
}
Then on the Angular side you make a symmetrical interpreter as a service and run your queries through it:
myApp.service('$getStuff',['$http',function($http){
this.query = function(url, data,callback){
$http.post(url, data).then(
function(result)
{
for(var key in data.Views)
{
document.getElementById(key).innerHTML(data.Views[key]);
}
callback(result.Model)
}
}
}]);
Super rough, but that's the idea.
"There are three kinds of lies: lies, damned lies and statistics."
- Benjamin Disraeli
|
|
|
|
|
Hi All,
I have to have date ranges selected multiple times in HTML5, Like for example if we have Start Date and End Date, like this, there should be multiple Start and End Dates Selected, if one Start and End Date is Selected, then the drop down (or that element) should allow me to select another one as long as I want one.
Any help would be appreciated thanks in advance my friends.
Here is my code to display one set of Date pickers for start and end:
var template;
if (paramType === 'Date Range') {
var multiple = "multiple='multiple'";
template =
'<div id="Param_' + Id + '">' +
'<div class="parameterHeader ui-widget-header ui-corner-top">' + paramDisplayName + '</div>' +
'<div class="parameterItem ui-widget-content ui-corner-bottom" ' + multiple + '>' +
'<div class="parameterFieldResize parameterField">' +
'<input class="parameterDateRangePicker clearable" placeholder="Start" type="text" name="' + paramName + '_1_Start" id="' + paramName + '_1_Start" />' +
'<input class="parameterDateRangePicker clearable" placeholder="End" type="text" name="' + paramName + '_1_End" id="' + paramName + '_1_End" />' +
'</div>' +<br />
'</div>' +
'</div>';
<pre>
this.JQElem = $(template);
initialParent.append(this.JQElem);
$('#' + paramName + '_1_Start').datepicker({
onSelect: function (dateText) {
$(this).trigger("input");
if (typeof me.values[this.id.split('_')[1]] === 'undefined')
me.values[this.id.split('_')[1]] = {};
me.values[this.id.split('_')[1]]['Start'] = dateText;
}
});
$('#' + paramName + '_1_End').datepicker({
onSelect: function (dateText) {
$(this).trigger("input");
if (typeof me.values[this.id.split('_')[1]] === 'undefined')
me.values[this.id.split('_')[1]] = {};
me.values[this.id.split('_')[1]]['End'] = dateText;
}
});
$("#" + paramName + '_1_Start').change(function (event) {
var dateString = this.value;
if (/^\d{1,2}\/\d{1,2}\/\d{2}$/.test(dateString)) {
dateString = dateString.substring(0, dateString.length - 2) + '20' + dateString.substring(dateString.length - 2, dateString.length);
this.value = dateString;
}
if (isValidDate(dateString)) {
if (typeof me.values[paramName + '_1'] === 'undefined')
me.values[this.id.split('_')[1]] = {};
me.values[this.id.split('_')[1]]['Start'] = dateString;
} else if (typeof me.values[this.id.split('_')[1]] !== 'undefined' && typeof me.values[this.id.split('_')[1]]['Start'] !== 'undefined') {
if (typeof me.values[this.id.split('_')[1]]['End'] !== 'undefined')
delete me.values[this.id.split('_')[1]];
else
delete me.values[this.id.split('_')[1]];
}
});
$("#" + paramName + '_1_End').change(function (event) {
var dateString = this.value;
if (/^\d{1,2}\/\d{1,2}\/\d{2}$/.test(dateString)) {
dateString = dateString.substring(0, dateString.length - 2) + '20' + dateString.substring(dateString.length - 2, dateString.length);
this.value = dateString;
}
if (isValidDate(dateString)) {
if (typeof me.values[this.id.split('_')[1]] === 'undefined')
me.values[this.id.split('_')[1]] = {};
me.values[this.id.split('_')[1]]['End'] = dateString;
} else if (typeof me.values[this.id.split('_')[1]] !== 'undefined' && typeof me.values[this.id.split('_')[1]]['End'] !== 'undefined')
if (typeof me.values[this.id.split('_')[1]]['End'] !== 'undefined')
delete me.values[this.id.split('_')[1]];
else
delete me.values[this.id.split('_')[1]];
});
The same thing was possible for Multi select Dropdown, here is the code for that, but when I am trying to do the same on the Date pickers its not working, any Idea is going to be greatly helpful, a code snippet, a link or even suggestion is going to be very helpful thanks in advance my friends.
var template;
if (paramType === 'Date Range') {
var multiple = "multiple='multiple'";
template =
'' +
'' +
' ' +
' ' +
'<input class="parameterDateRangePicker clearable" placeholder="Start" type="text" name="' + paramName + '_1_Start" id="' + paramName + '_1_Start" />' +
'<input class="parameterDateRangePicker clearable" placeholder="End" type="text" name="' + paramName + '_1_End" id="' + paramName + '_1_End" />' +
' ' +
' ' +
' ';
//Insert HTML
this.JQElem = $(template);
initialParent.append(this.JQElem);
$('#' + paramName + '_1_Start').datepicker({
onSelect: function (dateText) {
$(this).trigger("input");
if (typeof me.values[this.id.split('_')[1]] === 'undefined')
me.values[this.id.split('_')[1]] = {};
me.values[this.id.split('_')[1]]['Start'] = dateText;
}
});
$('#' + paramName + '_1_End').datepicker({
onSelect: function (dateText) {
$(this).trigger("input");
if (typeof me.values[this.id.split('_')[1]] === 'undefined')
me.values[this.id.split('_')[1]] = {};
me.values[this.id.split('_')[1]]['End'] = dateText;
}
});
$("#" + paramName + '_1_Start').change(function (event) {
//convert to 4 digit year (always will be in the 20's)
var dateString = this.value;
if (/^\d{1,2}\/\d{1,2}\/\d{2}$/.test(dateString)) {
dateString = dateString.substring(0, dateString.length - 2) + '20' + dateString.substring(dateString.length - 2, dateString.length);
this.value = dateString;
}
if (isValidDate(dateString)) {
if (typeof me.values[paramName + '_1'] === 'undefined')
me.values[this.id.split('_')[1]] = {};
me.values[this.id.split('_')[1]]['Start'] = dateString;
} else if (typeof me.values[this.id.split('_')[1]] !== 'undefined' && typeof me.values[this.id.split('_')[1]]['Start'] !== 'undefined') {
if (typeof me.values[this.id.split('_')[1]]['End'] !== 'undefined')
delete me.values[this.id.split('_')[1]];
else
delete me.values[this.id.split('_')[1]];
}
});
$("#" + paramName + '_1_End').change(function (event) {
//convert to 4 digit year (always will be in the 20's)
var dateString = this.value;
if (/^\d{1,2}\/\d{1,2}\/\d{2}$/.test(dateString)) {
dateString = dateString.substring(0, dateString.length - 2) + '20' + dateString.substring(dateString.length - 2, dateString.length);
this.value = dateString;
}
if (isValidDate(dateString)) {
if (typeof me.values[this.id.split('_')[1]] === 'undefined')
me.values[this.id.split('_')[1]] = {};
me.values[this.id.split('_')[1]]['End'] = dateString;
} else if (typeof me.values[this.id.split('_')[1]] !== 'undefined' && typeof me.values[this.id.split('_')[1]]['End'] !== 'undefined')
if (typeof me.values[this.id.split('_')[1]]['End'] !== 'undefined')
delete me.values[this.id.split('_')[1]];
else
delete me.values[this.id.split('_')[1]];
});
Thanks,
Abdul Aleem
"There is already enough hatred in the world lets spread love, compassion and affection."
modified 31-Oct-16 16:02pm.
|
|
|
|
|
I want to create a single page on which i can perform full crud operation using dropdownlist, radiobuttonlist, checkbox ,checkbox inside dropdown in a gridview.
and at the left side of each row in gridview should be insert, delete and update.
and should be a button on which click we can see the deleted rows.
please send the code with database script file.
|
|
|
|
|
Member 12736856 wrote: please send the code with database script file. Sorry this is not a "code to order" forum.
|
|
|
|
|
Member 12736856 wrote: please send the code with database script file. It is incredibly rude to ask people to do all the work for you. I hope this is not what you meant and that you will edit your post and ask a more specific question to help you get past where you are stuck.
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
I have an MVC view page (Views\DataForms\Index.cshtml) with an HTML form that just contains a couple of selects and a hidden element. I'm trying to POST the form to action 'Edit' in controller 'DataForms'. My form tag contains method="post" and action="DataForms\Edit".
The form includes a basic button with type="submit" and value="Submit", nothing unusual. But when I submit the form, the navigation fails with the error page showing the Requested URL as: http://localhost:49796/DataForms/Index/DataForms/Edit
So, the URL I'm actually requesting, is instead being appended to the URL of the current page where my form is. What might be causing this? I've searched the internet and I don't see anyone else raising this issue. Thanks.
|
|
|
|
|
You're specifying a relative URL as the action of your form. That will be resolved relative to the current URL.
Use the action URL helper to specify the form action:
<form method="POST" action="@Url.Action("Edit", "DataForm")">
...
</form>
UrlHelper.Action Method (System.Web.Mvc)[^]
Or use the BeginForm helper:
@using (Html.BeginForm("Edit", "DataForm", FormMethod.Post))
{
...
}
FormExtensions.BeginForm Method (System.Web.Mvc.Html)[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Have a toggle switch where I want to show textboxes based on what is selected on the toggle switch and need help on it. If Contract is selected I want to show contract row, if Order is select order row. Also how do I replace the row on top of the other row depending on which is selected from the toggle switch. So if I select Contract I want the Contract row/textbox to show obviously and if Order is selected, I want the Order row/textbox to show in the same spot as the Contract row/textbox.
Here is the code I have so far but need help completing it:
<div class="col-md-3">
<label class="switch2">
<input class="switch-input2" type="checkbox" id="contractselection" name="contractselection" runat="server"/>
</label>
</div>
<div class="col-xs-4">
<div class="contractrow">
<label for="exampleInputCity">Contract:*:</label>
<asp:TextBox ID="contractnumber" class="form-control" name="contractnumber" placeholder="" runat="server"></asp:TextBox>
</div>
<asp:RequiredFieldValidator ID="rfvcontractnumber" runat="server" ControlToValidate ="contractnumber" ErrorMessage="Please enter a Contract">
</asp:RequiredFieldValidator>
<div class="orderrow">
<label for="exampleInputCity">Solicitation:*:</label>
<asp:TextBox ID="ordernumber" class="form-control" name="ordernumber" placeholder="" runat="server"></asp:TextBox>
</div>
<asp:RequiredFieldValidator ID="rfvsolicitationnumber" runat="server" ControlToValidate ="ordernumber" ErrorMessage="Please enter a Order">
</asp:RequiredFieldValidator>
</div>
</div>
</div>
javascript:
<script type="text/javascript">
$(function () {
$(".contractrow").show();
$(".switch-input2").click(function () {
if ($(this).is(":checked")) {
$(".contractrow").show();
} else {
$(".solicitationrow").hide();
}
});
});
</script>
|
|
|
|
|
Try something like this:
$(function(){
var showTheRow = function(isChecked){
$(".contractrow").toggle(isChecked);
$(".orderrow").toggle(!isChecked);
};
$(".switch-input2").click(function(){
showTheRow(this.checked);
});
showTheRow($(".switch-input2").is(":checked"));
});
.toggle() | jQuery API Documentation[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I have a couple of toggle switches: one with Yes/No option and the other with Delivery/Purchase option. I know that you can use the ControlName.Checked but that just inserts True or False. How do I do this when these are the options.
Here are my toggle switch code for Purchase/Delivery:
<label class="switch">
<input class="switch-input" type="checkbox" id="orderselection" name="orderselection" runat="server" />
</label>
and Yes/No:
<label for="exampleOrderNumber">Are Redelegations Authorized?<label for="exampleInputCity">:</label>
<label class="switch">
<input class="switch-input" type="checkbox" id="authredelegation" name="authredelegation" runat="server" />
</label>
|
|
|
|
|
Use the ternary operator:
C#:
command.Parameters.AddWithValue("@OrderSelection", orderselection.Checked ? "Purchase" : "Delivery");
VB:
command.Parameters.AddWithValue("@OrdersSelection", If(orderselection.Checked, "Purchase", "Delivery"))
NB: For "yes/no" options, it's best to stick with the boolean value. Just declare your database column as a bit .
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Greetings gurus,
I have a requirement to collect information from users by presenting a form to them.
Upon completing the form and hitting the submit button, the content of their submission is stored in the db and at the same time sent as an email attachment all at once.
Is this possible?
If yes, does anyone know what I need to modify in the code below?
The code is not fully cooked but I need some guidance on how to submit the record and at same time sending the contents of the record as an attachment via email.
Thanks for your awesome help.
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
Dim table As New DataTable()
Using con = New SqlConnection(ConfigurationManager.ConnectionStrings("PersonnelPolicyDB").ConnectionString)
Using cmd = New SqlCommand("usp_AddABCD", con)
Using da = New SqlDataAdapter(cmd)
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.AddWithValue("@oderno", "orderno.text")
cmd.Parameters.AddWithValue("@orderdate", "orderdate.text")
da.Fill(table)
End Using
End Using
End Using
End Sub
Dim table As New DataTable()
Using con = New SqlConnection(ConfigurationManager.ConnectionStrings("PersonnelPolicyDB").ConnectionString)
Using cmd = New SqlCommand("usp_GetABCD", con)
Using da = New SqlDataAdapter(cmd)
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.AddWithValue("@orderno", "orderno.text")
da.Fill(table)
End Using
End Using
End Using
End Sub
Private Sub SendPDFEmail(dt As DataTable)
Using sw As New StringWriter()
Using hw As New HtmlTextWriter(sw)
Dim companyName As String = "my Company"
Dim orderNo As Integer = 2303
Dim sb As New StringBuilder()
sb.Append("<table width='100%' cellspacing='0' cellpadding='2'>")
sb.Append("<tr><td align='center' style='background-color: #18B5F0' colspan = '2'>Order Sheet</td></tr>")
sb.Append("<tr><td colspan = '2'></td></tr>")
sb.Append("<tr><td>Order No:")
sb.Append(orderNo)
sb.Append("</td><td>Date: ")
sb.Append(DateTime.Now)
sb.Append(" </td></tr>")
sb.Append("<tr><td colspan = '2'>Company Name : ")
sb.Append(companyName)
sb.Append("</td></tr>")
sb.Append("</table>")
sb.Append("<br />")
sb.Append("<table border = '1'>")
sb.Append("<tr>")
For Each column As DataColumn In dt.Columns
sb.Append("<th style = 'background-color: #D20B0C;color:#ffffff'>")
sb.Append(column.ColumnName)
sb.Append("</th>")
Next
sb.Append("</tr>")
For Each row As DataRow In dt.Rows
sb.Append("<tr>")
For Each column As DataColumn In dt.Columns
sb.Append("<td>")
sb.Append(row(column))
sb.Append("</td>")
Next
sb.Append("</tr>")
Next
sb.Append("</table>")
Dim sr As New StringReader(sb.ToString())
Dim pdfDoc As New Document(PageSize.A4, 10.0F, 10.0F, 10.0F, 0.0F)
Dim htmlparser As New HTMLWorker(pdfDoc)
Using memoryStream As New MemoryStream()
Dim writer As PdfWriter = PdfWriter.GetInstance(pdfDoc, memoryStream)
pdfDoc.Open()
htmlparser.Parse(sr)
pdfDoc.Close()
Dim bytes As Byte() = memoryStream.ToArray()
memoryStream.Close()
Dim mm As New MailMessage("NoReply@domain.com", "myemail@domain.com")
mm.Subject = "iTextSharp PDF"
mm.Body = "iTextSharp PDF Attachment"
mm.Attachments.Add(New Attachment(New MemoryStream(bytes), "iTextSharpPDF.pdf"))
mm.IsBodyHtml = True
Dim smtp As New SmtpClient()
smtp.Host = "myhostname"
smtp.EnableSsl = False
Dim NetworkCred As New System.Net.NetworkCredential()
NetworkCred.UserName = "myusername"
NetworkCred.Password = "mypassword"
smtp.UseDefaultCredentials = True
smtp.Credentials = NetworkCred
smtp.Port = 25
smtp.Send(mm)
End Using
End Using
End Using
End Sub
|
|
|
|
|
It's rather easy. Write code to save to the database and then write code to send it as an email. There are samples of both online all over the place.
Where are you stuck?
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
Man, RyanDev, it is beginning to sound like you just sit on my posts so you can tell me how easy it is and where to go get it.
I know how to google.
But my question is NOT strictly about how to save data and send email.
If you really wanted to help, you would have read my post completely.
What I would like to do is save the user's data and AT SAME TIME send the data a user just entered as A .PDF ATTACHMENT.
They are not asking to click to save the records and then click to send the records just inserted as an attachment.
They want it done in ONE click.
|
|
|
|
|
samflex wrote: They want it done in ONE click. I understood that from the beginning. Why is this hard for you. In one click, save the data to the database and then send the email. We all do this all the time. It is pretty standard. We won't write the code for you so you have to explain where you are stuck.
Just saying, "I want to..." does not mean anything. So, if you know how to google, do it then. It is like you call your mechanic on the phone and say, "I want to drive my car to the store." What in the world do you think the mechanic will say?
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
Please do me a favor Ryan.
Next time you see a post from me please avoid commenting on.
How can you say, "we wont write the code for you?
How many lines of code I did I post?
Besides, I asked for ideas.
I have never seen you suggest a solution since I have been coming here.
There are just annoying so called experts like you who feels big by making people feel little.
Even your simple-minded suggestion of saving data and emailing it once again suggests you have no clue what issues I am having.
I know how to save data and email the contents. I am not sure you know what it means to convert user's contents into pdf and email them as attachments.
|
|
|
|
|