Question

I am passing form values to stored procedure parameters and i have a problem... I want to execute this stored procedure from a C# program. I am VERY new at this, so any help on why I am getting these errors is greatly appreciated.

Stored Procedure Parameters

ALTER PROCEDURE [dbo].[User] 
(
   @pname varchar(100),
   @Colour varchar(100),
   @Sheet varchar(100),
   @Size varchar(100),
   @GSM varchar(100),
   @pcost varchar(100),
   @is_deleted bit,
   @DOC datetime
)   
as begin 
INSERT INTO [SMjobcard].[dbo].[Papertype]
        ([pname]
       ,[Colour]
       ,[Sheet]
       ,[Size]
       ,[GSM]
       ,[pcost]
       ,[is_deleted]
       ,[DOC])
 VALUES
       (@pname,@Colour,@Sheet,@Size,@GSM,@pcost,@is_deleted,@DOC)
 END

C#

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Data.OleDb;

public partial class Admin : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
protected void Button1_Click(object sender, EventArgs e)
{
    String ConnString =   ConfigurationManager.ConnectionStrings["conString"].ConnectionString;
    SqlConnection con = new SqlConnection(ConnString);
    //SqlConnection con = new SqlConnection("Data Source=(local);Initial    Catalog=SMjobcard;Integrated Security=True");
    //con.Open();
    SqlCommand cmd = new SqlCommand(ConnString);
    cmd.CommandType = CommandType.StoredProcedure;
    cmd.CommandText = "User";
    cmd.Parameters.Add("@pname", SqlDbType.VarChar,50).Value = TextBox2.Text.Trim();
    cmd.Parameters.Add("@Colour", SqlDbType.VarChar,50).Value = TextBox3.Text.Trim();
    cmd.Parameters.Add("@Sheet", SqlDbType.VarChar,50).Value = TextBox4.Text.Trim();
    cmd.Parameters.Add("@Size", SqlDbType.VarChar,50).Value = TextBox5.Text.Trim();
    cmd.Parameters.Add("@GSM", SqlDbType.VarChar,50).Value = TextBox6.Text.Trim();
    cmd.Parameters.Add("@pcost", SqlDbType.VarChar,50).Value = TextBox7.Text.Trim();
    cmd.Parameters.Add("@is_deleted", SqlDbType.Bit).Value = true;
    cmd.Parameters.Add("@DOC", SqlDbType.DateTime).Value = TextBox9.Text.Trim();
    cmd.Connection = con;
    try
    {
        con.Open();
        cmd.ExecuteNonQuery();
        lblmsg.Text = "Record inserted successfully";
    }
    catch (Exception ex)
    {
       ex.ToString();
    }
    finally
    {
        con.Close();
        con.Dispose();
    }  
   }
}

** i have an error for converting string to decimal,string to Boolean,string to decimal plz help me **

Was it helpful?

Solution

Please check your table design and then create the Stored Procedure.it may be possible that your are inserting wrong data to wrong column.means string data to bool column.so please check.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top