|
don't know if this is due to poor db design or not but I have been struggling since last night to update some records from by selecting the values of records to be updated from a dynamically populated dropdownlist from a lookup table.
Essentially, we have three tables called Courses, Instructors and CourseInstructor tables.
CourseInstructor table is a bridge table between Courses and Instructor tables.
So, when adding courses and instructors to their various tables, their foreign keys are automatically added to the bridge table.
This seems to work fine so far.
However, users are having difficulties making changes to these tables.
For instance, if a user wishes to replace one instructor with another, she has not been to do so for far. After an update, the message indicates successful update the instructor names don't change.
Any ideas what I could have done wrong with the code below?
<asp:TemplateField HeaderText="Instructor">
<EditItemTemplate>
<asp:DropDownList ID="ddlInstructors" runat="server" AppendDataBoundItems="True" DataSourceID="SubjectDataSource"
DataTextField="InstructorName" DataValueField="InstructorId">
</asp:DropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lblInstructors" runat="server" Text='<% #Bind("InstructorName") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:SqlDataSource ID="sqlDataSourceloc" runat="server"
ConnectionString="<%$ ConnectionStrings:DBConn %>"
SelectCommand="SELECT locationId, Location FROM Locations order by location asc"></asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:DBConnectionString %>"
UpdateCommand = "Update tblCourseInstructor Set CourseId = @CourseId where (CourseId =@CourseId) Update tblCourseInstructor set InstructorId=@InstructorId where (instructorId=@instructorId and courseId = @courseId)"
SelectCommand="select l.locationid,c.CourseId, i.instructorId,CourseName, i.instructorname, dbo.fnFormatDate(t.trainingDates, 'MON/DD/YYYY') trainingDates, t.trainingTime,CourseDescription from Courses c, tblLocations l, TrainingDates t, Instructors i, CourseInstructor ci where l.locationid = c.locationid and c.dateId = t.dateId and i.instructorid = ci.instructorId and c.courseid=ci.courseid and YEAR(t.trainingDates) = YEAR(getDate())"
FilterExpression="LocationId = '{0}'" >
<FilterParameters>
<asp:ControlParameter ControlID="ddlLocation" Name="LocationId" PropertyName="SelectedValue" Type="Int32" />
</FilterParameters>
<UpdateParameters>
<asp:Parameter Name="CourseId" Type="Int32" />
<asp:Parameter Name="instructorId" Type="Int32" />
</UpdateParameters>
</asp:SqlDataSource>
<asp:SqlDataSource ID="SubjectDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:DBConn %>"
SelectCommand="SELECT instructorId, InstructorName FROM dbo.Instructors order by InstructorName">
</asp:SqlDataSource>
Then I tried updating it from codebehind with code below
Protected Sub GridView1_RowUpdating(ByVal sender As Object, ByVal e As GridViewUpdateEventArgs) Handles GridView1.RowUpdating
Dim ddAssigned As DropDownList = DirectCast(GridView1.Rows(e.RowIndex).FindControl("ddlInstructors"), DropDownList)
e.NewValues("instructorId") = ddAssigned.SelectedValue
SubjectDataSource.DataBind()
End Sub
but got the following error:
'SqlDataSource1' unless UpdateCommand is specified.
Any ideas how do I fixt this one?
|
|
|
|
|
I'm taking a big guess here on this, but I think this is your problem.
I wanna say that it's a bad design, but I haven't seen the design, but the CourseID should say the same if your just updating the teacher
UpdateCommand = _
"Update tblCourseInstructor Set CourseId = @CourseId where (CourseId =@CourseId) " & _
"Update tblCourseInstructor set InstructorId=@InstructorId where (instructorId=@instructorId and courseId = @courseId)"
<pre>
UpdateCommand = _
"Update tblCourseInstructor set InstructorId=@InstructorId where courseId = @courseId)"
</pre>
|
|
|
|
|
Hi,
Thanks for your time responding to my question.
My design idea was based on the fact that this is a many to many relationship between teacher and course.
A teacher can teach more than one courses just as a course can be thought by more than one teacher.
This made it many to many. So, there is one way I know to bridge them and that's by creating a third table that has foreign key for both tables.
How would you have designed them?
|
|
|
|
|
I think you have it backwards, and should try flipping them around.
Set the teacher id, then set the course id
If you change the course id first, then the teacher id will not change because you changed the course id, and your using the same parameter @courseid which is static or the same value.
As far as design goes, I'd have to see the map, or see the whole picture to tell. Jorgen is really good at that, you would have to prepare a well worded question in database forum for that.
I think it's a SQL or database issue here.
|
|
|
|
|
Just my opinion, I'm not the best at this.
I think a course is a course, like a shoe being sold online.
You can have the same course, like shoe sizes,
The teacher is just a category, or a shoe size, and the time and day of the course is like the color of a shoe.
So take a course marketing 101,
marketing101-time-teacher
1 table
1 record marketing 101 with time and teacher id
Join 1 more table time represented by time id
Join 1 more table teacher represented by teacher id
Then just update the marketing 101 with the correct time and teacher.
|
|
|
|
|
I want to insert some JavaScript code for validation. Here it is :
script language="javascript">
function checkEmail() {
var email = document.getElementById('txtEmail');
var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
if (!filter.test(email.value)) {
alert('Please provide a valid email address');
email.focus;
return false;
}
}</script>
and the code in body is :
<input type='text' id='txtEmail'/>
<input type='submit' name='submit' onclick='Javascript:checkEmail();'/>
Now I want to check for validation on submit button but I also want to run code written in .cs page for
<asp:Button ID="BtnSubmit" runat="server" onclick="Button1_Click" Text="Register Now" />
|
|
|
|
|
Hi,
Something like this should do it:
<asp:Button ID="BtnSubmit" runat="server" onClientClick="return checkEmail();" onClick="Button1_Click" Text="Register Now" />
If your checkEmail routine returns true, then a post back occurs - which will run the serverside code in Button1_Click.
If the validation fails, then no postback will occur.
Hope it helps.
|
|
|
|
|
Dear readers,
Could anyone provide me an example how I can call multiple OData services from within a .net API asynchronously? I’m using DataServiceQuery’s to get all the data from the external OData services. I have tried using:
public static class QueryExtension
{
public static Task<IEnumerable<TResult>>; QueryAsync<TResult>(this DataServiceQuery<TResult> query)
{
return Task<IEnumerable<TResult>>.Factory.FromAsync(query.BeginExecute, query.EndExecute, null);
}
}
But my webapi gets locked that way.
Best regards,
Rémy
|
|
|
|
|
|
Hi i am new to dot net i have a question that how does an aspx page executes without an error even after removing page load method.
Thanks in advance.
|
|
|
|
|
Because of the framework - your page inherits from the common page that has a default Load event handler...
I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is. (V)
|
|
|
|
|
|
Am working in 3 tier architecture in asp.net.i wanted to learn mvc and which version i will start first (mvc 1,2,3,etc).which is the best way to study mvc in asp.net.
|
|
|
|
|
Video tutorials are the best.
If you can spend few dollars then go with Pluralsight. The best way of learning, as per my experience
http://www.pluralsight.com/training/Courses#aspdotnet
There ASP.Net MVC official site is also very good. Step by step Walk through step.
http://www.asp.net/mvc/tutorials/mvc-5/introduction/getting-started
Search in Code project articles. There are plenty of articles. Follow these tutorials and try to build an application from the ground, is the best way to learn.
I am currently working with MVC 4. I recommend you to start with MVC 5 which is almost an year old.
Good luck.
|
|
|
|
|
Thank u Mr Swinkaran
|
|
|
|
|
|
Hi folks, can someone please help, I have been going round in circles with this and I’m new to ASP & C#.
Could someone please create a basic example of how to display a web user controls i.e. dropdown lists on one page and the results displaced on a second page within a Gridview.
I have store proc for the GridView, big thanks as I am losing the plot here!!!
USE [TyreSannerSQL]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER Procedure [dbo].[SearchResults] @Width int, @Profile int, @Diamete int, @Speed nvarchar, @CustPostcode nvarchar (50)
As
Begin
SELECT Suppliers.SupplierID, Suppliers.SupplierName, Product.Width, Product.Profile, Product.Diamete, Product.Speed, Product.Brand, Product.TyreModel, Product.TyreType,
Product.RollingResistance, Product.WetGrip, Product.NoiseEmission, Product.ProductUnitSalePrice
FROM Product INNER JOIN
Suppliers ON Product.SupplierFK = Suppliers.SupplierID
WHERE Width = @Width
and Product.Profile = @Profile
and Product.Diamete = @Diamete
and (Product.Speed = @Speed
or COALESCE(@Speed,'') = '')
and Suppliers.SupplierDistrict = LEFT(@CustPostcode,2)
ORDER BY Product.ProductUnitSalePrice ASC
End
|
|
|
|
|
When the dropdown changes you can use Response.Redirect("") to go to the page with the grid and pass the parameters through the query string.
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
I am working on a MVC Json web service and in the web service I am making a call to Active directory. What I need to do is determine, in my code, all possible common, non-exception, types of login return values possible when an AD user attempts to login. Also, where can I find a list of all common login errors (i.e. User Not Found, etc.) and how to access the login error type in my json web service.
modified 15-Sep-14 22:25pm.
|
|
|
|
|
hello, i have ASP.net source code but i cant run it with (IIS)8, it says i don't have full permission in web.config file...And I did a lot of possible thins to fix it right but it couldnt...i would appreciate any help
|
|
|
|
|
You really need to post the exact error message.
It's usually from not setting the file permissions on the disk drive for IIS_ANONYMOUS and the app_pool identity.
You really need to search for setting permissions, the AppPool\YouNameHere is the name of the application pool, in which you go tot he IIS Manager and look up the name, or it's the name of the website you made.
[EDIT]
If your web server is a member of a domain, you should unlink it before using the code below, then relink it when done.
icacls.exe test.txt /grant "IIS AppPool\DefaultAppPool":(OI)(CI)M
cmd /c icacls test.txt /grant "IIS AppPool\DefaultAppPool:(OI)(CI)M"
You should Google the above and read up on it before applying the command, so you get the exact result you want. or else you'll have to go back and delete a bad idea to keep your site secure. Just search icals.exe
You also have to setup permissions for IIS_Anonymous for read only. I searched for a link for that
https://adminspeak.wordpress.com/tag/iis-7-5-best-practices/[^]
|
|
|
|
|
|
Hi,
I have freelance job which is about an online food order. Someone who wants to order food have to be registired. I want to add registered users to the role "member". I can handle the registiration process but I cannot add to the role member.
How can I achieve this?
I've searched but couldn't find it.
|
|
|
|
|
|
Thanks for your reply actually I tried a similar method this:
Roles.AddUsersToRoles
However that gave en exception. Until you've posted me, I did not realize your suggest.
Thanks for your help.
|
|
|
|