Codechef4u is a community for computer professionals,by computer professionals,just like you; who loves sharing and helping each others,Join them
Share your post

Invalid object name ‘tableName’ with Database

I am trying to create a Stored Procedure for a newly created database. However the SSMS intellisense does not recognize many tables from new database.

-- =============================================
-- Author:                    Nagnath Kendre
-- Create date: 24/10/2015
-- Description: Create leave type
-- =============================================
CREATE PROCEDURE CreateLeaveType
            -- Add the parameters for the stored procedure here
 @LeaveTitle [nvarchar](100),
 @Description [nvarchar](200),
 @UserId UNIQUEIDENTIFIER
AS
BEGIN
            -- SET NOCOUNT ON added to prevent extra result sets from
            -- interfering with SELECT statements.
SET NOCOUNT ON;
 
INSERT INTO dbo.LeaveType
        (
                                    LeaveTitle,
                                    [Description],
                                    AddedBy,
                                    CreatedDate)
                                    values
                                    (@LeaveTitle,
                                     @Description,
                                     @UserId,
                                     GETDATE()
                                    )
 
END
GO


i.e for table LeaveType I am getting error like

Invalid object name 'LeaveType'.

 

Fix:

Edit -> IntelliSense -> Refresh Local Cache
This should refresh the data cached by Intellisense. 

What is INSERT statement conflicted with the FOREIGN KEY constraint?

If your are getting following error,

The INSERT statement conflicted with the FOREIGN KEY constraint "ABC". The conflict occurred in database "XYZ", table "XYZ", column 'Id'.

 Solution:

For example your database has two tables


Leave table LeaveType is foreign key and Primary Key in LeaveType table is ID, When you try to enter Leave type that is not exist in First Table(LeaveType) you will get above error.

i.e when you try to enter data like following


Solution for this error is while inserting data into second table use only existing data (data from Primary Kay table).

 

Unable to get gridview footer values in RowCommand

Error: 

Unable to get gridview footer values in RowCommand

Solution 1:

Code in the page load should look like this, check whether you are binding the grid view correctly in the Page Load.

if (!IsPostBack)

{

//Bind Grid data here

  LoadGrid();

}

 Solution 2:

You are not using sender in your find control code line.

Example your code like:

    TextBox txtname = (TextBox)GrdProducts.FooterRow.FindControl("txtAddProductName");

   TextBox txtprice = (TextBox)GrdProducts.FooterRow.FindControl("txtAddprice");

This should be:

TextBox txtprice = (TextBox)((GridView)sender).FooterRow.FindControl("txtAddprice");