|
Take a look at http://www.databaseanswers.org/data_models/[^] and see if there is one that meets your needs. It is a good site to study the structures of databases.
And yes put lot of effort into designing your data structure, think through your requirements before you start creating your database.
Never underestimate the power of human stupidity -
RAH
I'm old. I know stuff - JSOP
|
|
|
|
|
In the first DropdownList should display the Countries and in the second should display Cities based on the Country like .. USA then display just cities in USA . well i am getting undefined in dropdown city the Question is why i am getting always undefined in City dropDown list ?
here is countrol :
<pre> public ActionResult Index()
{
Details();
return View();
}
public void Details (
{
var model = db.GetUniversities().ToList();
List<SelectListItem> li = new List<SelectListItem>();
li.Add(new SelectListItem { Text = "Please select Country",Value="0"});
foreach (var item in model)
{
li.Add(new SelectListItem { Text = item.Country, Value = item.Id.ToString()});
ViewBag.state = li;
}
}
[HttpPost]
public JsonResult GetCity (int id)
{
var ddlCity = db.GetUniversities().Where(x => x.Id == id).ToList();
List<SelectListItem> licities = new List<SelectListItem>();
if (ddlCity != null)
{
foreach (var x in ddlCity)
{
licities.Add(new SelectListItem { Text = x.City, Value = x.Id.ToString() });
}
}
return Json(new SelectList(licities, "Text", "Value"));
}
here view
<div class="form-group">
@Html.LabelFor(model => model.Country, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DropDownListFor(model => model.Country, ViewBag.state as List<SelectListItem>, new { style = "width: 200px;" })
@Html.ValidationMessageFor(model => model.Country, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.City, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DropDownListFor(model => model.City, new SelectList(string.Empty, "Value", "Text"), "--Select City--", new { style = "width:200px" })
@Html.ValidationMessageFor(model => model.City, "", new { @class = "text-danger" })
here jQuery
$(document).ready(function () {
$("#Country").change(function () {
$("#City").empty();
$.ajax({
type: 'POST',
url: '@Url.Action("GetCity")',
dataType: 'json',
data: { id: $("#Country").val() },
success: function (city) {
$.each(city, function (i, city) {
$("#City").append('<option value="' + city.Value + '">'+ city.Text + '</option>');
});
},
error: function (ex) {
alert('Failed.' + ex);
}
});
return false;
})
});
|
|
|
|
|
You may have to set an ID attribute to your DropDownListFor control so you can reference them in your jQuery code. For example:
@Html.DropDownListFor(model => model.Country, ViewBag.state as List<SelectListItem>, { @id="ddlCountry", @class="YourCSSClassName" })
then in your jQuery, you can access it like this:
$("#ddlCountry").change(function () {
});
|
|
|
|
|
i am still getting the same error .. where should i exactly write the id .. could you more explain please
i thank you very much in advanced
|
|
|
|
|
You need to give ID's to all your controls that you reference in your jQuery and then use the IDs just like what I demonstrated. If you followed that and you are still getting error, then post your updated code here and show us which line you are getting the error.
|
|
|
|
|
Hi Vincent,
so i am still getting the same problem thus let me show you what i have changed .
i did what you have told me . could you check once again and in SQL there are some Countries and Cities like USA -> Bosten , Germany -> Frankfurt etc....
the View :
<div class="form-group">
@Html.LabelFor(model => model.Country, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DropDownListFor(model => model.Country, ViewBag.state as List<SelectListItem>
, new {@id ="ddlCountry", @class = "form-control" })
<div class="form-group">
@Html.LabelFor(model => model.City, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DropDownListFor(model => model.City, new SelectList(string.Empty, "Value", "Text"), "--Select City--",
new {@id ="ddlCity", @class = "form-control" })
The jQuery :
$(document).ready(function () {
$("#ddlCountry").change(function () {
$("#ddlCity").empty();
$.ajax({
type: 'POST',
url: '@Url.Action("GetCity")',
dataType: 'json',
data: { id: $("#ddlCountry").val() },
success: function (city) {
$.each(city, function (i, city) {
$("#ddlCity").append('<option value="' + city.Value + '">'+ city.Text + '</option>');
});
},
error: function (ex) {
alert('Failed.' + ex);
}
});
return false;
})
});
and with Controls haven't changed :
public void Details ()
{
var model = db.GetUniversities().ToList();
List<SelectListItem> li = new List<SelectListItem>();
li.Add(new SelectListItem { Text = "Please select Country",Value="0"});
foreach (var item in model)
{
li.Add(new SelectListItem { Text = item.Country, Value = item.Id.ToString()});
ViewBag.state = li;
}
}
[HttpPost]
public JsonResult GetCity (int id)
{
var ddlCity = db.GetUniversities().Where(x => x.Id == id).ToList();
List<SelectListItem> licities = new List<SelectListItem>();
licities.Add(new SelectListItem { Text = "--Select City--", Value = "0" });
if (ddlCity != null)
{
foreach (var x in ddlCity)
{
licities.Add(new SelectListItem { Text = x.City, Value = x.Id.ToString() });
}
}
return Json(new SelectList(licities, "Text", "Value"));
|
|
|
|
|
What error are you getting now? Still undefined? Please be specific also for the errors that you are currently getting.
|
|
|
|
|
it's fine now . i have got it .
i thank you a lot
|
|
|
|
|
That's great! Glad to be of help!
|
|
|
|
|
Hello,
This issue occurs when a request process with "&" char (URL With "&").
e.g.
http://PSL.com/CALCC&test&Calendar2018_AR.pdf
Our requirement is to allow URL With "&" request using HTTP modules in IIS.
We don't want to modify web.config file for resolving this issue.
Means validation request=false in web.config. We need to solve this issue using HTTP module.
Need your suggestion on this issue.
Thanks,
Yuvraj
|
|
|
|
|
|
Thanks for replay. Please suggest for handle this issue using HTTP Module class.
|
|
|
|
|
Hello;
I have 2 different class libraries (data model, business services) in my solution. There is an app config file in the data model. I wonder if I can read it inside of business services? (the error is configuration manager does not exist.)
I can add values into web config which is in the web API project in this solution but this time I need to add web API project in the reference of business services. It gives a circular dependency error.
|
|
|
|
|
It depends what is hosting the code. If the code is running under IIS then you need the values in the web.config, if the code is running inside an EXE then the values need to be in a "processname.exe.config" file.
|
|
|
|
|
Greetings again,
I am still having some issues with this project.
This time, the issue is with pulling records by passing date values.
Everything else seems to work well.
We have two date parameters, date_start and date_end
A user can enter just value for start date only, end date only or date range between start date and end date.
The issue is that if a user enters start date, and clicks search, we get No data found message.
If user enters either value for end date or date range between start date and end date, the system hangs.
On the DB, using SSMS, if I enter a value for start date, I get results.
Similarly, if I enter value for either end date or date range between start date and end date, I get results very quickly.
When I put a debugger on my asp.net code, it returns the exact same value as the value I get when I run it from SSMS.
For instance,
Here is a value for start and end dates:
start date: 2014-05-05 10:34:03
end date: 2014-05-05 10:35:52
These values are the same when I query from the DB and as well as when I put debugger on my code.
The data type for these dates is DateTime2(0).
Any ideas why this is not working from my app?
Here are some code snips:
'//stored proc WHERE clause
WHERE 1 = 1
AND ((@uuid IS NULL OR qp.uuid Like '%' + @uuid + '%')
AND (@callerlist IS NULL OR qp.call_list_id Like '%' + @callerlist + '%')
AND (@phone IS NULL OR cl.phone_number Like '%' + @phone + '%')
AND (@start IS NULL OR startttime >= @start)
AND (@Endd IS NULL OR endtime <= @Endd)
AND (@calltype IS NULL OR c.id Like '%' + @calltype + '%')
AND cl.phone_number IS NOT NULL)
'/
<asp:TextBox id="date_start" style="width:150px;" class="form-control alignleft" runat="server" />
<asp:TextBox id="date_end" style="width:150px;" class="form-control alignleft" runat="server" />
'/VB:
Private Sub SearchCustomers()
Dim constr As String = ConfigurationManager.ConnectionStrings("ppmtest").ConnectionString
Using con As New SqlConnection(constr)
Using cmd As New SqlCommand()
Dim sql As String = "spGetLogs"
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.AddWithValue("@uuid", suuid.Text)
cmd.Parameters.AddWithValue("@callerlist", caller_list_id.Text)
cmd.Parameters.AddWithValue("@phone", phonenumber.Text)
cmd.Parameters.AddWithValue("@start", date_start.Text)
cmd.Parameters.AddWithValue("@Endd", date_end.Text)
cmd.Parameters.AddWithValue("@calltype", call_type.SelectedValue)
'Response.Write(sql)
'Response.End()
cmd.CommandText = sql
cmd.Connection = con
Using sda As New SqlDataAdapter(cmd)
Dim dt As New DataTable()
sda.Fill(dt)
gvCustomers.DataSource = dt
gvCustomers.DataBind()
End Using
End Using
End Using
End Sub
As usual, any help is greatly appreciated
|
|
|
|
|
Why are you using text strings for dates instead of DateTime types, and textboxes instead of Date pickers?
|
|
|
|
|
Hi Richard,
Thanks for your response however, I am not sure I understand your question.
Where did you see me use text strings?
|
|
|
|
|
In your command parameters e.g:
cmd.Parameters.AddWithValue("@start", date_start.Text)
, and the textboxes in your form.
|
|
|
|
|
Hmm, still confused.
The textboxes in my form are populated by selecting date from datepicker.
How would have coded the form?
|
|
|
|
|
Try something like:
Dim startDate As DateTime
If DateTime.TryParse(date_start.Text, startDate) Then
cmd.Parameters.AddWithValue("@start", startDate)
Else
cmd.Parameters.AddWithValue("@start", DBNull.Value)
End If
DateTime.TryParse Method (System) | Microsoft Docs[^]
If the date picker's format doesn't match the server's regional settings, then you may need to use DateTime.TryParseExact Method[^] instead.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Thank you so much sir.
That worked.
It is spitting out way too many records.
Is it possible to do something like this on the stored proc:
Year(startttime) >= Year(@start) on the stored proc?
For instance, I queried with this range:
14-05-05 10:34:03 for start date and
2014-05-30 12:16:21 for end date
and it produced almost 700,000 records. First time, it timed out.
|
|
|
|
|
I suspect the problem is with the start date, which only has a two-digit year. DateTime.TryParse doesn't know which part is the year, the month, and the day, so it has to guess based on your computer's regional settings.
On my computer, parsing 14-05-05 10:34:03 returns 2005-05-14 10:34:03 , which is obviously not what you wanted.
Try changing your date picker so that it always formats the date with four-digit years. If you can't do that, then you'll need to use DateTime.TryParseExact[^] with a list of possible formats.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Did you say that start_date has two digit year because of the data type which is
DateTime2(0). ?
If so, I can remove the 2 so we get 4 digit year.
Thanks for your help sir.
|
|
|
|
|
No, I said that start date has a two-digit year because that's what you showed: 14-05-05 10:34:03 .
(datetime2(0) is the correct SQL type to use; the "2" has nothing to do with the number of digits in the year.)
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
That's not what I showed sir.
I showed four digit year:
start date: 2014-05-05 10:34:03
end date: 2014-05-05 10:35:52
The year from my example is 2014
|
|
|
|
|