|
I am having problem trying to use a linq to sql datasource on a detailsview control in a C# 2010 web form new application. What I want to be able to do is use the linq to sql datasource listed below to update records in the table called 'Atts". According to a Devexpress online tutorial that I looked at, it said to remove the ' new statement' in the select statement, and then you can do an edit.
The following is the select statement: Select="new (Att_id, Prior_Cutoff_Date)" statement.
However visual studio 2010 will not allow me to remove the 'new' statement. I am guessing the reason why is the column called 'Att_id' is an identity column.
Thus can you tell me what I can do so I can setup the edit feature to work? Is there something I can do with the linq to sql dataource to work around the identity column? Should I have a second linq to sql data source where I would have one linq to sql datasource for inserting and another dataource for updating? Let me know what your recommendation is and/or point me to a reference I can use to solve my problem
Here is the code I have so far:
<pre>
<asp:LinqDataSource ID="LinqDataSource1" runat="server" ContextTypeName="Support.AttDataContext"
Select="new (Att_id, Prior_Cutoff_Date)"
TableName="Atts" Where="Att_id == @Att_id"
EnableUpdate="True">
<UpdateParameters>
<asp:SessionParameter Name="Att_id" SessionField="AttID" />
</UpdateParameters>
<WhereParameters>
<asp:SessionParameter Name="Att_id" SessionField="AttID" Type="Int32" />
</WhereParameters>
</asp:LinqDataSource>
<asp:DetailsView ID="DetailsView1" runat="server" Height="50px" Width="125px" EnableModelValidation="False"
AutoGenerateRows="False" DataSourceID="LinqDataSource1" BorderStyle="Solid" HorizontalAlign="Center"
DefaultMode="Edit">
<Fields>
<asp:TemplateField HeaderText="Att ID">
<ItemTemplate>
<asp:TextBox ID="TextBoxAttid" runat="server" Text='<%# Eval("Att_id") %>'
BorderStyle="None"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Prior Cutoff Date" SortExpression="Prior_Cutoff_Date">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("Prior_Cutoff_Date") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Prior_Cutoff_Date") %>'></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
</Fields>
</asp:DetailsView>
</pre>
|
|
|
|
|
Looks like your SQL Statement is not valid. I went and looked up a reference and rewrote it. Not tested, I have nothing to test it with, just off the top of my head.
TableName = "Atts",
Select="new (Att_id, PriorCutoff_Date FROM Atts),
WHERE Att_id=@Att_id,
|
|
|
|
|
I thought the linq to sql data source was correct since it initially loaded the detialsview control with the information I am looking for. I will try your suggestion and see what I find out.
|
|
|
|
|
I've never used linq, but I know it's popular in India, where I see hundreds of linq questions. I stopped binding controls years ago, because of certain side affects that occur during deployment. Keep in mind that I've been doing this for over 10 years now, so I use a direct connection to the sql connector.
Never the less, It is a quality solution. I looked up the documentation on the control binder, and that was the correct use of binding a select statement with more than 1 column to request,
Select new(column1, column2),
Where column1 = 'blah',
Tablename = "Att",
Update = True,
Insert = True,
Delete = True,
I remember reading, to use the Update = True, in which I assume that the control will automatically generate Update, insert and delete SQL commands for you, you just have to make a button, give it a name and id, and click on it to generate a function in code behind, then you can use code behind to attach to the linq control, and perform your operation.
Sample Update command
UPDATE Att (column2='blah') WHERE Column1=56;
I think you had an Identity Question as well, that is an automatic increment to the first column, which is usually an id of the record number, that is indexed in the table. Each time you add or insert a record, the Identity will calculate the next id number to use, and automatically insert that number into the column of the new record.
|
|
|
|
|
The user of the new web form pages wants the buttons you click on, outside of the detailsview control. Thus to accomplish this task, I am trying to determine what method and/or event is called within the detailsview control when a record is updated. Can you tell me and/or point me to a reference so I can see where theis occurs?
|
|
|
|
|
This is the closest I can find on the web. It's like Deja Vu, I've seen this question before on Code Project, about 3 weeks ago. Only they had the data part figured out, just needed the external button. Same Discussion group, Around October 25th 2011
http://www.devx.com/dotnet/Article/37796/1954[^]
|
|
|
|
|
i have site map like
="1.0"="utf-8"
<siteMapNode url="~/DE/index.aspx" title="DE Home" description="DE Home">
<siteMapNode url="~/DE/Parts.aspx" title="Part" description="DE Part" />
<siteMapNode url="~/DE/SubParts.aspx" title="Subpart" description="DE Subpart" />
</siteMapNode>
<siteMapNode url="~/US/index.aspx" title="US Home" description="US Home">
<siteMapNode url="~/US/Parts.aspx" title="Part" description="US Part" />
<siteMapNode url="~/US/SubParts.aspx" title="Subpart" description="US Subpart" />
</siteMapNode>
<siteMapNode url="~/UK/index.aspx" title="UK Home" description="UK Home">
<siteMapNode url="~/UK/Parts.aspx" title="Part" description="UK Part" />
<siteMapNode url="~/UK/SubParts.aspx" title="Subpart" description="UK Subpart" />
</siteMapNode>
</siteMapNode>
</siteMap>
everything is working fine but last link in my breadcrum is showing as link rather it should show as label or span. how to get control over the generation of site navigation link and detect the link is last link and if the link is last link then span will be render other wise anchor tag will be render for site navigation in the page. how to achieve it. thanks
tbhattacharjee
|
|
|
|
|
It's just an XML file, it only provides the data for the site map.
You have to format the data by writing a program load the xml, and using upperbounds on the element count, to create a span tag on the last element, or tweak the site map control in properties.
You can try injecting a span tag
<siteMapNode url="~/UK/SubParts.aspx" title="Subpart" description="UK Subpart" />
But the server might reject it.
|
|
|
|
|
How did you generate that file??
Look, it is full of errors:
- There is no opening tag for the closing </siteMap> .
- The first content line gets closed a few lines farther down:
<siteMapNode url="~/DE/index.aspx" title="DE Home" description="DE Home">
..
</siteMapNode>
- That holds true for the following blocks, too.
- And I do not see an opening tag for last </siteMapNode> .
Conclusion:
Correct the XML of that file, and it will likely work.
|
|
|
|
|
i have small site which i am testing in my local machine.
my file structure is like
index.aspx
DE/index.aspx
US/index.aspx
UK/index.aspx
my routing code
void Application_Start(object sender, EventArgs e)
{
RouteTable.Routes.MapPageRoute("default", "home", "~/default.aspx");
RouteTable.Routes.MapPageRoute("DE_Home", "DE", "~/DE/Index.aspx");
}
i want that when i will type url like http://localhost:7745/home then my root index.aspx should load. for this i route like below
RouteTable.Routes.MapPageRoute("default", "home", "~/default.aspx");
it is working fine.
i want that when i will type url like http://localhost:7745/DE then root/DE/Index.aspx should load but in this case my routing is not working. i want to load index.aspx fine in DE folder which is in root folder. i think there is some problem in my routing for that
what i need to change in the routing like
RouteTable.Routes.MapPageRoute("DE_Home", "DE", "~/DE/Index.aspx");
please guide me what should i write that when i will type http://localhost:7745/DE or http://localhost:7745/de or http://localhost:7745/De then my index.aspx file should load from de folder......thanks
tbhattacharjee
|
|
|
|
|
Route tables are objects, and the have to be created first. I was looking at your code and it didn't look right. Routes have to be added to a collection or class.
This is the sample at msdn. I was going to write a sample, but I think I would get it wrong. I assume it's the global file, you can write this in a class as well, and call the class.
Be careful, I tried it before, and it backfired on me, with bots not seeing the routes, and cataloging the raw url, and some other stuff.
Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
RegisterRoutes(RouteTable.Routes) // You have to register your routes
End Sub
Shared Sub RegisterRoutes(ByVal routes As RouteCollection)
Dim urlPattern As String
Dim categoryRoute As Route
urlPattern = "Category/{action}/{categoryName}"
// You have to add a new object to the webserver for the route to process
categoryRoute = New Route(urlPattern, New CategoryRouteHandler)
routes.Add(categoryRoute)
End Sub
|
|
|
|
|
Hello Nishant
1)I had download demo VB project - 23.6 Kb and it is not working can you please explain how to run the same ?
2)i am developing a project for hotel in that i want to display whether hotel is available for that day or not and to show price against that day in calendar control .Can you please send me a sample code which helps me to completed this assignment .
Hotel availability is store in different table with price .So i want to bind the price against that day .Can you please suggest me a way?
Regards
Aarti Ostwal
|
|
|
|
|
Ostwal Aarti wrote: Hello Nishant
It's better when you write direct to author's article which you have download.
I Love T-SQL
"VB.NET is developed with C#.NET"
If my post helps you kindly save my time by voting my post.
|
|
|
|
|
Hi
Our Website has refrenced multiple dll's .Is there any chance to decrease performance of websites with multiple dll's refrencing. i need to improve performance of WebSite.Please suggest me better way.
Regards,
Vishnu.
|
|
|
|
|
Are these ddls are .Net ddls or com components ?
if they are managed code (.Net ddls), it will not make less effect to performance, but if they are unmangaed code, it will affect the performance.
Click "Accept Answer" button! if solves your problem...
Regards,
Anil
Complex problems often have simple solutions.. think quitely to find them...
|
|
|
|
|
The use of DLLs is rarely something that you have much choice about and is less likely to affect performance than other things such as the format of your web pages, speed of your database, efficiency of your code etc. I don't know of any tools that you could use to check this but Google is always a good starting point.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
Well unless you can write your own dll, you don't have much choice.
What's inside the DLL is up to the author, and I've seen some really bad DLL code posted on other forums. I've also been the victim of really bad DLL code, so I write my own now.
The most common error are memory leaks, because they forget to destroy objects. The 2nd most common is the lack of understanding the page life cycle, so they create object in page load, and not page init.
Best bet is get ahold of the source, and take a peek.
|
|
|
|
|
Hello,
I wants to retrive regional language settings in my code. For that i used WMI.
I tried below code.
in page load : GetLoggedInUserCulture();
private static CultureInfo GetLoggedInUserCulture()
{
string folderName = string.Empty;
string sID = GetWindowsLoggedInUserSID();
object locale = Registry.Users.OpenSubKey(sID + @"\Control Panel\International").GetValue("Locale");
int lCID = int.Parse(locale.ToString(), NumberStyles.HexNumber);
CultureInfo ci = new CultureInfo(lCID);
return ci;
}
private static string GetWindowsLoggedInUserSID()
{
string userName = null;
string sID = null;
try
{
ManagementScope oMs = new ManagementScope();
ObjectQuery oQuery = new ObjectQuery("Select UserName from Win32_ComputerSystem");
ManagementObjectSearcher oSearcher = new ManagementObjectSearcher(oMs, oQuery);
ManagementObjectCollection oReturnCollection = oSearcher.Get();
ManagementClass mc = new ManagementClass(oMs, new ManagementPath("ServerBinding"), null);
foreach (ManagementObject oReturn in oReturnCollection)
{
userName = oReturn["UserName"].ToString().ToLower();
}
userName = userName.Substring(userName.LastIndexOf(@"\") + 1);
oQuery = new ObjectQuery("Select SID, Name from Win32_Account where Name = '" + userName + "'");
oSearcher = new ManagementObjectSearcher(oMs, oQuery);
oReturnCollection = oSearcher.Get();
foreach (ManagementObject oReturn in oReturnCollection)
{
if (oReturn["SID"] != null)
{
sID = oReturn["SID"].ToString();
}
}
}
catch (Exception)
{
throw;
}
return sID;
}
but oReturn["UserName"] and oReturn["SID"] return me null value.
Do i need to add anything in webconfig. or any thing else am missing.. please help me
|
|
|
|
|
That code is running on the server. That means that your user must be a user of that server or the domain the server is a member of. But generally, users of a web application are different from the Windows user.
Better use cookies or a database entry for storing the language/regional settings. Show your page in a default language of your choice, and let the user decide which language he prefers, and store that information.
|
|
|
|
|
Good Idea, and nice shot with the code. But reading the registry from a web app is a no no. May work in the web dev (F5), but not in production mode on a production server.
The post above is correct. Let the user choose, then write the cookie
|
|
|
|
|
thanks for the reply
but its client requirement that they want to disply data acooring to regional setting language.
My code is working for another project but its not working in another porject where actually i need language. ;(
not sure why so
|
|
|
|
|
Go back to the beginning, and check the registry value, you may be able to get the value from the browser using javascript / jquery / json, and transmit the value back for storage. Just keep stepping through the process until something clicks. Check your Global call for the culture value, and make sure it matches your select case or switch, or route mapping.
No insult intended, but I think that will backfire on you later on down the road. ASP.net keeps tightening the security screws, so one day on a server update, it may fail at like 3am in the morning. Then you will flash back at my warning, and slap yourself in the head.
|
|
|
|
|
i tries to get regional settings in javascript , it workes but javascript runs after pageload.
i iwant that value before page load done.
i want to apply that language 1st time.
i tried to store that valaue in javascript but it gets after page load. ;(
|
|
|
|
|
You can run javascript as client startup script - head tag, and with javascript reload the page with the correct culture, via url change, or set a session variable after that.
You can use some magic like a modal popup saying sensing personal settings, and then make the switch. Use some artwork to make it look cool.
First just get the mechanics working for after the culture is known, and then polish it it with culture detection.
Those are the only Ideas I have.
|
|
|
|
|
Hi,
Is Visual Source Safe 2005 Free?
Maulik Dusara
|
|
|
|
|