471,077 Members | 759 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,077 software developers and data experts.

Invalid object name 'Product'.

HI I'M NEWBIES in visual Basic with Sql Server
i try to make a database with stored procedure and whan i run the program the give an error


"Invalid object name 'Product'."

i dont know how to fix it here is my code
Dim sqlcon As New SqlClient.SqlConnection
sqlcon.ConnectionString = "Data Source=WISEMAN\SQLEXPRESS;Initial Catalog=Product;Integrated Security=True;Pooling=False;uid=uid;pwd=pwd "
Dim cmd As New SqlClient.SqlCommand
cmd.Connection = sqlcon
cmd.CommandType = CommandType.StoredProcedure
cmd.CommandText = "insertcustomer"
cmd.Parameters.AddWithValue("@Productid", TextBox1.Text)
cmd.Parameters.AddWithValue("@detail", TextBox2.Text)
sqlcon.Open()
cmd.ExecuteScalar()
cmd.ExecuteNonQuery()
sqlcon.Close()

the error at line is cmd.executescalar()
My database name is product
my name for my storedprocedure is insertcustomer
Code for insertcustomer
ALTER PROCEDURE dbo.InsertCustomer
(

@ProductID int output,
@detail varchar(50)
)


AS
SET NOCOUNT ON

INSERT INTO Productdetail
(detail)
VALUES
(@detail);

IF @@ROWCOUNT>0 AND @@ERROR>0

SELECT @Detail = detail

From Productdetail
Where (ProductID =SCOPE_IDENTITY())

if u have any idee please tell me
May 23 '07 #1
2 2962
DeMan
1,806 1GB
Hi shadwise,

Welcome to thescripts. I'm sure you will find a wealth of information ion the various forums here. I am moving this thread to the SQL server forum. You will still be able to access this particular thread through the introductions page, but future questions should be directed to the appropriate forum (which you will find by selecting "forums" on the blue bar near the top of your screen.

I hope the experts in the SQL server forum can help with your query!!
May 23 '07 #2
almaz
168 Expert 100+
...i dont know how to fix it here is my code...
if u have any idee please tell me
Does your server or database have case-sensitive collation? Please copy/paste complete error description.
I'm not sure about "Invalid object name 'Product'" problem, but there are several other problem worth mentioning:
  • Wrap SqlConnection and SqlCommand scope with using (C# keyword, don't know correct VB syntax)
  • Parameter "ProductID" should be created with Direction = ParameterDirection.Output
  • You don't need to specify "uid" and "pwd" in connection string as long as you are using integrated security.
  • Why do you execute stored procedure twice? Just call cmd.ExecuteNonQuery()
  • You don't assign inserted ProductID value to @ProductID parameter. I think your SP should look like:
    Expand|Select|Wrap|Line Numbers
    1. ALTER PROCEDURE dbo.InsertCustomer
    2. (
    3. @ProductID int output,
    4. @detail varchar(50)
    5. )
    6. AS
    7. SET NOCOUNT ON
    8.  
    9. INSERT INTO Productdetail
    10. (detail)
    11. VALUES
    12. (@detail);
    13.  
    14. IF @@ROWCOUNT>0
    15.   SET @ProductID = SCOPE_IDENTITY()
May 23 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

reply views Thread by archway | last post: by
5 posts views Thread by Nick Flandry | last post: by
1 post views Thread by samarthkumar84 | last post: by
3 posts views Thread by Gustaf | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.