我将表单值传递给存储过程参数,我有一个问题... 我想从C#程序执行此存储过程。 我对此非常陌生,所以对我为什么会收到这些错误的任何帮助都非常感谢。
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
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();
}
}
}
**我有一个错误,将字符串转换为十进制,字符串为布尔值,字符串为十进制plz帮助我**
答案 0 :(得分:0)
请检查您的表设计,然后创建存储过程。您可能正在向错误的列插入错误的数据。将字符串数据转换为bool列。请检查。