|
|
I have a C#.net 2010 web form application that I need to add two tables to the database. This application uses linq to sql. Can you tell me if I want to add these two new tables to the sql server 2008 r2 database, do I
1. Need to remove the original .dbml file and recreate the .dbml file?
2. I would think I can just add two tables to the database and somehow refresh the existing .dbml file. If this possible?
Whatever your answer is to the question, can you tell me how to solve this problem?
|
|
|
|
|
classy_dog,
double click on the dbml file and on the view menu choose server explorer add a link to the server your database is modeled from (you may already have one), you can click in any white space in the dbml diagram and look at the properties->connection->connection string to get the connection string. Once you have the server connection you can just drag the table(s) into the diagram.
|
|
|
|
|
I am trying to edit values in a row of a GridView, Gender DropDownList which is filled with values "Male" and "Female" is giving following error :
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
Line 65: DropDownList cmbType = (DropDownList)GridView1.Rows[e.RowIndex].FindControl("cmbType");
Line 66:
Line 67: customer.Update(Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Values[0].ToString()), txtName.Text, cmbGender.SelectedValue, txtCity.Text, cmbType.SelectedValue);
Line 68: GridView1.EditIndex = -1;
Line 69: FillCustomerInGrid();
Source File: d:\ASP.NET Examples\LoginExp\CustomerData.aspx.cs Line: 67
Stack Trace:
[NullReferenceException: Object reference not set to an instance of an object.]
CustomerData.GridView1_RowUpdating(Object sender, GridViewUpdateEventArgs e) in d:\ASP.NET Examples\LoginExp\CustomerData.aspx.cs:67
System.Web.UI.WebControls.GridView.OnRowUpdating(GridViewUpdateEventArgs e) +131
System.Web.UI.WebControls.GridView.HandleUpdate(GridViewRow row, Int32 rowIndex, Boolean causesValidation) +908
System.Web.UI.WebControls.GridView.HandleEvent(EventArgs e, Boolean causesValidation, String validationGroup) +809
System.Web.UI.WebControls.GridView.OnBubbleEvent(Object source, EventArgs e) +163
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +56
System.Web.UI.WebControls.GridViewRow.OnBubbleEvent(Object source, EventArgs e) +119
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +56
System.Web.UI.WebControls.LinkButton.OnCommand(CommandEventArgs e) +106
System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String eventArgument) +175
System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +31
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +32
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +242
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3825
Please help me solve this error.Thanks in advance.
|
|
|
|
|
As explained here http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.datakeys.aspx[^]
When the DataKeyNames property is set, the GridView control automatically creates a DataKey object for each row in the control. The DataKey object contains the values of the field or fields specified in the DataKeyNames property. The DataKey objects are then added to the control's DataKeys collection. Use the DataKeys property to retrieve the DataKey object for a specific data row in the GridView control.
The reason for null reference exception in the above code could be due to not setting the DataKeyNames property but accessing the DataKeys[e.RowIndex] value at
customer.Update(Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Values[0].ToString())
Try setting the DataKeyNames as shown in above reference like
datakeynames="CustomerID"
|
|
|
|
|
you can't use .ToString() method and set it to a null value,
GridView1.DataKeys[e.RowIndex].Values[0] is passing a null value!
set DataKeys for your gridview!
|
|
|
|
|
I have a Modal popup in my .aspx Page which opens on Click of a Button (btnNew). Modal popup Contains a Gridview with a blankraow added by Default, and a Button (btnAddNew), What I want is I want to add a new row on (btnAddnew) click.. which does so, but the Probem is Modal popup get disappeared.
And have to click (btnNew) to pop it ip again,which shows the new row added in Gridview..
I want the Modal popup to remin same untill I save the records.
plss Help
Sheringkapoting...
|
|
|
|
|
The ajax model popup extender has a habit of resetting back to hidden during postback.
You have to modelPopup.show() the extender in your button function to keep it in block mode, to keep it visible.
|
|
|
|
|
Procedure or function expects parameter that was not supplied why it arise and if arise how to resolve it
|
|
|
|
|
Supply the expected parameter.
Given that you have not shown the line of code in question we have no way of knowing the answer. If it's a call to a system API method then take a look at the documentation to find out why. If it is code belonging to some other developer then ask them.
|
|
|
|
|
OK I am supplying my code with stored proc here:
My stored proc:
USE [UniqueCorp]
GO
/****** Object: StoredProcedure [dbo].[uspUpdateUser_Step2] Script Date: 06/05/2012 12:12:38 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[uspUpdateUser_Step2]
@userID uniqueidentifier,
@Username nvarchar(50),
@CompanyName nvarchar(50),
@Address nvarchar(100),
@Country nvarchar(50),
@State nvarchar(50) = '',
@City nvarchar(50) = '',
@MobileNo nvarchar(50) = '',
@TelephoneNo nvarchar(50) = '',
@Password nvarchar(50)
AS
set nocount on;
IF Exists (SELECT [ID] FROM dbo.Users WHERE [ID] = @userID)
begin
update dbo.Users
set
UserName=@Username,
CompanyName=@CompanyName,
[Address]=@Address,
Country=@Country,
[State]=@State,
City=@City,
Mobileno=@MobileNo,
TelephoneNo=@TelephoneNo,
Password=@Password
WHERE [ID] = @userID
end
GO
and the code behind is this.......
public static int AddUpdateUser(Users user)
{
SqlParameter prmUserId = new SqlParameter("@userID", SqlDbType.UniqueIdentifier);
prmUserId.Value = user.ID;
SqlParameter prmUsername = new SqlParameter("@Username", SqlDbType.NVarChar, 50);
prmUsername.Value = user.UserName;
SqlParameter prmCompanyName = new SqlParameter("@CompanyName", SqlDbType.NVarChar, 50);
prmUsername.Value = user.CompanyName;
SqlParameter prmAddress = new SqlParameter("@Address", SqlDbType.NVarChar, 100);
prmUsername.Value = user.Address;
SqlParameter prmCountry = new SqlParameter("@Country", SqlDbType.NVarChar, 50);
prmUsername.Value = user.Country;
SqlParameter prmState = new SqlParameter("@State", SqlDbType.NVarChar, 50);
prmUsername.Value = user.State;
SqlParameter prmCity = new SqlParameter("@City", SqlDbType.NVarChar, 50);
prmUsername.Value = user.City;
SqlParameter prmMobileNo = new SqlParameter("@MobileNo", SqlDbType.Int, 50);
prmUsername.Value = user.MobileNo;
SqlParameter prmTelephoneNo = new SqlParameter("@TelephoneNo", SqlDbType.Int, 50);
prmUsername.Value = user.TelephoneNo;
SqlParameter prmPassword = new SqlParameter("@Password", SqlDbType.NVarChar, 50);
prmUsername.Value = user.Password;
return DataAccessObject.Execute("uspUpdateUser_Step2",prmUserId, prmUsername, prmCompanyName, prmAddress, prmCountry, prmState, prmCity, prmMobileNo, prmTelephoneNo,prmPassword);
}
Please help me the problem is still there...
Procedure or function expects parameter @Username That was not supplied.....
But i debug and confirm dat value is gone to the parameter @Username.So now i hav no idea about this ....
|
|
|
|
|
Firstly, this is a database problem and nothing to do with ASP.NET, so it is in the wrong forum. Secondly, you have given no indication where the error occurs. Thirdly, please use the correct <pre> tags around your code so it is readable, like this:
USE [UniqueCorp]
GO
SET ANSI_NULLS ON
GO
...
|
|
|
|
|
we have to assign default value as NULL
Create Procedure Sp_name
@Input1 varchar(100)=NULL
AS
BEGIn
//main Code
END
|
|
|
|
|
That sounds like a sql parameter your supplying is null, empty or nothing.
where @value is empty.
value=@value,
But like Richard said, you should walk your code, or show some code so we know what your taking about, or just Google it.
|
|
|
|
|
OK I am supplying my code with stored proc here:
My stored proc:
USE [UniqueCorp]
GO
/****** Object: StoredProcedure [dbo].[uspUpdateUser_Step2] Script Date: 06/05/2012 12:12:38 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[uspUpdateUser_Step2]
@userID uniqueidentifier,
@Username nvarchar(50),
@CompanyName nvarchar(50),
@Address nvarchar(100),
@Country nvarchar(50),
@State nvarchar(50) = '',
@City nvarchar(50) = '',
@MobileNo nvarchar(50) = '',
@TelephoneNo nvarchar(50) = '',
@Password nvarchar(50)
AS
set nocount on;
IF Exists (SELECT [ID] FROM dbo.Users WHERE [ID] = @userID)
begin
update dbo.Users
set
UserName=@Username,
CompanyName=@CompanyName,
[Address]=@Address,
Country=@Country,
[State]=@State,
City=@City,
Mobileno=@MobileNo,
TelephoneNo=@TelephoneNo,
Password=@Password
WHERE [ID] = @userID
end
GO
and the code behind is this.......
public static int AddUpdateUser(Users user)
{
SqlParameter prmUserId = new SqlParameter("@userID", SqlDbType.UniqueIdentifier);
prmUserId.Value = user.ID;
SqlParameter prmUsername = new SqlParameter("@Username", SqlDbType.NVarChar, 50);
prmUsername.Value = user.UserName;
SqlParameter prmCompanyName = new SqlParameter("@CompanyName", SqlDbType.NVarChar, 50);
prmUsername.Value = user.CompanyName;
SqlParameter prmAddress = new SqlParameter("@Address", SqlDbType.NVarChar, 100);
prmUsername.Value = user.Address;
SqlParameter prmCountry = new SqlParameter("@Country", SqlDbType.NVarChar, 50);
prmUsername.Value = user.Country;
SqlParameter prmState = new SqlParameter("@State", SqlDbType.NVarChar, 50);
prmUsername.Value = user.State;
SqlParameter prmCity = new SqlParameter("@City", SqlDbType.NVarChar, 50);
prmUsername.Value = user.City;
SqlParameter prmMobileNo = new SqlParameter("@MobileNo", SqlDbType.Int, 50);
prmUsername.Value = user.MobileNo;
SqlParameter prmTelephoneNo = new SqlParameter("@TelephoneNo", SqlDbType.Int, 50);
prmUsername.Value = user.TelephoneNo;
SqlParameter prmPassword = new SqlParameter("@Password", SqlDbType.NVarChar, 50);
prmUsername.Value = user.Password;
return DataAccessObject.Execute("uspUpdateUser_Step2",prmUserId, prmUsername, prmCompanyName, prmAddress, prmCountry, prmState, prmCity, prmMobileNo, prmTelephoneNo,prmPassword);
}
Please help me the problem is still there...
Procedure or function expects parameter @Username That was not supplied.....
But i debug and confirm dat value is gone to the parameter @Username.So now i hav no idea about this ....
|
|
|
|
|
I'm just using this one as an example only, it's not the problem.
The error message you got basically says that one of your parameters is null or nothing, and that a valid value is required in order to convert the value to a qualified parameter.
prmUsername.Value = user.Address; <- One of these values is null or nothing in your list of parameters, or is the wrong format for nvarchar.
If you wrap your code in the try, catch, you can trap the sql exception message, and it will tell you which parameter is the issue.
catch ex as sqlexception
|
|
|
|
|
The function or the Procedure is having some Parameters that are not been provided by your code while making call to that procedure.
Note: Signature of Fucntion/Procedure while Defining and While Declaring the fucntion donot matches.
- Happy Coding -
Vishal Vashishta
|
|
|
|
|
My Understanding [Please correct me if I am wrong]
The input validation is the mainly validating whether the controls are sending correct input for precessing or not.
Business rule is more specific rules like "if your order is less than certain minimum required order level then it will not be accepted and this minimum required order level will be calculated based on your previous records".
My belief [Please correct me if I am wrong]
The input validation is a perfect candidate that should be done on client side i.e. javascript but since someone can bypass the javascript it should the done on server side too. The business rules should be on the server side since there are/might be a lot of variables that will be considered.
Question:
The question now is, should we duplicate all the code for business rules on client side too just for the sake of having better responsiveness (I am aware of all the AJAX and async stuff but assuming that cannot be used). I mean someone got carried away and tell you that you take all the variables from DB, put them in hidden fields and then do all the business rule logic in javascript using these hidden field values on client side(even when this is being done on server side already). Now, to me this doesn't sound right. why should be duplicate all the logic just for the sake of having better responsiveness?
Every now and then say, "What the Elephant." "What the Elephant" gives you freedom. Freedom brings opportunity. Opportunity makes your future.
|
|
|
|
|
Rahul Rajat Singh wrote: Now, to me this doesn't sound right. why should be duplicate all the logic just for the sake of having better responsiveness?
Because your sitting in an office with the server located within a mile or Kilometer of your desk. You don't see the slow response and transmission times that a customer located several hundred miles away sees.
If you validate as many values as you can client side, the customer can fill out the form correctly, and make 1 postback to the server, resulting in a single successful transaction.
If you keep validating server side, it will result in several postbacks until the customer gets it rights, increasing unnecessary bandwidth by 400% or more.
Validating business rules client side gets a bit tricky, unless the business rules are simple and basic. In your javascript, you would need a way to fetch the rule via web service, or have all the rules prewritten, and make a switch to select the correct rule and run it.
[EDIT]
Rahul Rajat Singh wrote: put them in hidden fields and then do all the business rule logic in javascript using these hidden field values on client side
For a minimum value, using a hidden textbox with the minimum value in it would be handy to validate against on the client side. For minimum values, we just change the initial qty to the minimum value, and change the qty range from 1 to 100 to 5 to 100.
|
|
|
|
|
give me one example for globalization concept in asp.net...
|
|
|
|
|
|
|
Follow:
<a href="http://www.c-sharpcorner.com/uploadfile/santhi.m/globalizationusingasp.net11262005072116am/globalizationusingasp.net.aspx">http://www.c-sharpcorner.com/uploadfile/santhi.m/globalizationusingasp.net11262005072116am/globalizationusingasp.net.aspx</a>[<a href="http://www.c-sharpcorner.com/uploadfile/santhi.m/globalizationusingasp.net11262005072116am/globalizationusingasp.net.aspx" target="_blank" title="New Window">^</a>]
- Happy Coding -
Vishal Vashishta
|
|
|
|
|
I want learn asp.net and c# step by step. please give me tips to learn
|
|
|
|
|
The best book for C#:
1. C# 2010 Step by step - beginner
2. C# 4.0 in a nutshell - comprehensive coverage
for ASP.net
1. ASP.NET 4.0 Step by step
2. MCTS 70-515 self paced training kit
3. can't remember the name but a book from WROX P2P series on ASP.NET 4.0.
Some of recommendation:
Microsoft press' MCTS self paced learning kit books are awesome, do read them.
Microsoft press' Step by step series are good for beginners, do read them.
C# 4.0 in a nutshell is pretty good, read it cover to cover.
watch videos on ASP.NET website.
read the MVPs blogs (CP and MSFT)
follow code project daily religiously.
Video Tutorials:
1. "asp.net" official website contains very good videos.
2. "Lynda.com" also has some video series on asp.net but they are from very beginners perspective.
3. "Total Training" has some asp.net 2.0 videos which are pretty awesome to get to intermediate level.
4. I am snot sure about "VTC" but hopefully it might also have some videos on asp.net too.
Every now and then say, "What the Elephant." "What the Elephant" gives you freedom. Freedom brings opportunity. Opportunity makes your future.
|
|
|
|
|