Quantcast
Channel: ADO.NET, Entity Framework, LINQ to SQL, NHibernate
Viewing all articles
Browse latest Browse all 1698

Stored Procedure sql parameter

$
0
0

Hello I have a Stored Proc for the Registration Page, but I need ADO.NET to take values from various textboxes.
However, I'm recieving errors-

Here is my code-

public void InsertInfo()
    {
        String empdb = @"Data Source=USER-PC\SQLEXPRESS;Initial Catalog=EmployeeDB;Integrated Security=True";
        SqlConnection conn = new SqlConnection(empdb);
        SqlCommand cmd = new SqlCommand("bridge_Type", conn);
        cmd.CommandType = CommandType.StoredProcedure;


        try
        {
            conn.Open();
            cmd.Parameters.Add(new SqlParameter("@EmpID", TextBox1));
            cmd.Parameters.Add(new SqlParameter("@Name", TextBox1));
            cmd.Parameters.Add(new SqlParameter("@Mob2", TextBox1));
            cmd.Parameters.Add(new SqlParameter("@Email", TextBox1));
            cmd.Parameters.Add(new SqlParameter("@Emptype", dropdown1.SelectedValue));
            cmd.ExecuteNonQuery();
        }

        catch (System.Data.SqlClient.SqlException ex)
        {
            string msg = "Insert Error:";
            msg += ex.Message;
            throw new Exception(msg);

        }

        finally
        {
            if (conn != null)
            {
                conn.Close();
            }
        }

    }



    protected void Button1_Click(object sender, EventArgs e)
    {
        InsertInfo();
    }

This is my SP:

Create Procedure bridge_Type(
@EmpID INT,
@Name   varchar(50),
@Mob2   numeric(10,0),
@Email  varchar(50),
@Type   varchar(50)
)
AS 
DECLARE @TYPEID int
Set NOCOUNT OFF

BEGIN TRANSACTION

INSERT INTO dbo.EmpType VALUES (@Type)

SET @TYPEID = SCOPE_IDENTITY()

IF @@ERROR <> 0 
BEGIN     
ROLLBACK     
RETURN 
END 


Insert into dbo.Emp VALUES (@EmpID, @Name, @Mob2, @Email, @TYPEID)
IF @@ERROR <> 0
BEGIN 
ROLLBACK
RETURN
END

COMMIT 

Error: 

System.ArgumentException: No mapping exists from object type System.Web.UI.WebControls.TextBox to a known managed provider native type.

I'm sure it is wrong in ADO.NET conn because it works exactly the way I want, in SQL Server 2008

How'd I achieve this? Please help..


Viewing all articles
Browse latest Browse all 1698

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>