Click here to Skip to main content
15,892,927 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
SQL
//Stored procedure
ALTER PROCEDURE dbo.HDR_PROFILE_proc(@first_name varchar(15), @middle_name varchar(15), @last_name varchar(15),
@address varchar(150), @Mob_No varchar(15),@birthdate datetime , @gender bit, @email_id varchar(50), @user_id varchar(15), @password varchar(15), @confirm_pass varchar(15), @country varchar(15), @city varchar(15)  )
	
AS
insert into DSProfile.HDR_PROFILE(first_name , middle_name ,last_name ,address , contact_number ,birth_date , gender, email_id, user_name , password , confirm_password ,country , city )values(@first_name , @middle_name , @last_name ,
@address , @Mob_No ,@birthdate  , @gender , @email_id ,  @user_id, @password , @confirm_pass , @country , @city   )
RETURN

C#
//code
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;

public partial class _Default : System.Web.UI.Page
{
    SqlConnection con;
   
     
    protected void Page_Load(object sender, EventArgs e)
    {
        con = Connectivity.GetConnection();
        txt_userid.Enabled = false;
        txt_first_name.Focus();
       
    }

    protected void txtsubmit_Click(object sender, EventArgs e)
    {
        SqlCommand cmd = new SqlCommand("[dbo].[HDR_PROFILE_proc]", con);
        cmd.CommandType = CommandType.StoredProcedure;
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        //cmd.CommandText = "HDR_PROFILE_proc";
        
        cmd.Parameters.AddWithValue("@first_name", txt_first_name.Text);
        cmd.Parameters.AddWithValue("@middle_name", txt_middle_name.Text);
        cmd.Parameters.AddWithValue("@last_name", txt_last_name.Text);
        cmd.Parameters.AddWithValue("@address", txt_address.Text);
        cmd.Parameters.AddWithValue("@Mob_No", txt_mob_no.Text);
        cmd.Parameters.AddWithValue("@birthdate", Convert.ToString(txt_birthdate.Text));
        cmd.Parameters.AddWithValue("@gender", Rdo_gender.SelectedIndex);

        cmd.Parameters.AddWithValue("@email_id", txt_email.Text);

        if (Rdobtn_userid.Checked == true)
        {
            cmd.Parameters.AddWithValue("@user_name", txt_userid.Text);
            //cmd.Parameters.AddWithValue("@Login_with_email",'0');
        }
        //else
        //{ 
           // cmd.Parameters.AddWithValue("@Login_with_email",'1')
        //}
        
        cmd.Parameters.AddWithValue("@password", txt_pass.Text);
        cmd.Parameters.AddWithValue("@confirm_pass", txt_confirm_pass.Text);
        cmd.Parameters.AddWithValue("@country", txt_country.Text);
        cmd.Parameters.AddWithValue("@city", txt_city.Text);

        DataSet ds = new DataSet();
        da.Fill(ds); //exception ocuured here
        cmd.ExecuteNonQuery();
        con.Close();
    }   
}
Posted
v2
Comments
faisal23 7-Nov-12 6:36am    
check connection string, database name, stored procedure name
Member 9579525 7-Nov-12 6:50am    
Thank u...
Member 9579525 8-Nov-12 0:14am    
will it give error if i wont write schema name before procedure name? and in insert query?
e.g
create procedure [schema name].[procedure name]
as
insert into [schema name][table name] values()
fjdiewornncalwe 8-Nov-12 9:10am    
If no schema is given, then dbo is by default checked.
Please ask question in a correct way.

From the error, anyone can say that there is no stored procedure in the database, which you are trying to execute.

Thanks...

SqlCommand cmd = new SqlCommand("[dbo].[HDR_PROFILE_proc]", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText="ur stored procedure name"; //add this
SqlDataAdapter da = new SqlDataAdapter(cmd);
 
Share this answer
 
I think you don't need to specify [dbo]. when you are calling stored procedure of DBO schema.
you can use either
C#
SqlCommand cmd = new SqlCommand("dbo.HDR_PROFILE_proc", con);

or
C#
SqlCommand cmd = new SqlCommand("HDR_PROFILE_proc", con);


Hope that helps
Milind
 
Share this answer
 
You have done this
C#
DataSet ds = new DataSet();
        da.Fill(ds);  
        cmd.ExecuteNonQuery();
        con.Close();

Try this (Without inserting data what you are trying to fill in dataset)

cmd.ExecuteNonQuery();
DataSet ds = new DataSet();
da.Fill(ds);  
con.Close();
 
Share this answer
 
Hi,
If you have same issue,
SQL
Could not find stored procedure error
.

Please check the "ConnectionString". Which u provided in Web.config.

Check the ConnectionString name, Database name, Server name.




Thanks & Regards
Ganesh Pate
 
Share this answer
 
Comments
Richard Deeming 16-Aug-16 9:08am    
Your answer duplicates the very first comment posted to the question - nearly FOUR YEARS AGO!
The problem may be that you are using

C#
cmd.CommandType = CommandType.StoredProcedure;

If you use this type then the SqlCommand expects nothing in the CommandText field but the stored procedure name. No parameters are allowed. So you need to use:

C#
cmd.CommandType = CommandType.Text;

then the command should be something like

C#
cmd.CommandText = "EXEC dbo.sp_procedurename @param1, @param2,..."
 
Share this answer
 
Comments
CHill60 31-May-19 8:01am    
"No parameters are allowed." … really? I don't think you're right there.
Richard Deeming 31-May-19 8:57am    
No, that is correct. If you set the command type to "stored procedure", the command text cannot contain anything other than the name of the stored procedure.

Of course, you can still pass parameters to the stored procedure. You just can't include them in the command text.

CommandType Enum | Microsoft Docs[^]
"When the CommandType property is set to StoredProcedure, the CommandText property should be set to the name of the stored procedure to be accessed."
Richard Deeming 31-May-19 8:58am    
Of course, that doesn't change the fact that the code in the question doesn't add any parameters to the command text. So this answer is still wrong. :)
CHill60 3-Jun-19 5:52am    
That was sort of what I was getting at. The answer could be misinterpreted as "you can't pass parameters to a stored procedure", especially as the OP has used Parameters so well (unusual on here even if it was 7 yearss ago :-) ). Having it as text as in the solution is almost encouraging string concatenation :sigh:.

Ironically, Solution 3 was voted down and yet was the only solution that noticed that the OP hadn't set the CommandText at all (it was commented out)
Richard Deeming 3-Jun-19 6:44am    
I don't agree with your comment about solution 3: the OP had already passed the command text to the SqlCommand constructor. There's no need to set it again. :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900