无法使用存储过程在SQl中插入值 [英] Unable to Insert values in SQl using Stored Procedure
本文介绍了无法使用存储过程在SQl中插入值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
下面的书面存储过程,无法插入Sql中的值.
-------------------------------------------------- -------------------------------
命名空间 WebApplication1
{
公共 部分 class Trans:System.Web .UI.页面
{
SqlConnection con = 新 SqlConnection(ConfigurationManager.ConnectionStrings [" ].ToString());
受保护的 无效 Page_Load(对象发件人,EventArgs e)
{
}
公共 静态 void 消息(字符串消息,控制cntrl)
{
ScriptManager.RegisterStartupScript(cntrl,cntrl.GetType(),"
," +消息+ " ');",受保护的 无效 Button1_Click(对象发件人,EventArgs e)
{
如果(PatID_NO.Text!= " )
{
SIDC a = 新 SIDC();
int n;
n = a.valid_re_int(PatID_NO.Text);
如果(n > 3 )
{
消息(" , this );
返回;
}
其他
PatID_NO.Focus();
}
其他
PatID_NO.Focus();
尝试
{
如果(NameTxtBx.Text == " || ToTxtBx0.Text == " || DropDownList1.SelectedIndex == " && PatID_NO.Text == " )||( Convert.ToUInt64(PatNo.Text)< = 0 )||(Convert.ToUInt64(PatNo.文本)">> " ,返回;
}
其他
{
尝试
{
字符串 Patient_name = NameTxtBx.Text,Export_TO = ToTxtBx0.Text,repType = RadioButtonList2.SelectedValue;
ulong PatNoVal = Convert.ToUInt64(PatNo.Text);
今天的DateTime = Convert.ToDateTime(DateTime.Now.ToShortDateString());
int ?idcount = -1;
int ? replay_To_type = Int16 .Parse(DropDownList1.SelectedValue);
MembershipUser用户ID = Membership.GetUser();
// Message("Block 1",this);
尝试
{
TransDataContext db = 新 TransDataContext();
尝试
{
var q = db.Transaction(患者名称,导出名称,重播类型,repType,PatNoVal,idcount);
}
捕获
{
消息(" ,此);
}
}
捕获
{
消息(" , this );
}
// Message(交易号" + idcount.ToString(),此);
ClientScript.RegisterStartupScript(此 .GetType()," , 警报(您的ID为:" + idcount + " , true );
// TextBox1.Text =交易编号参考" +"\ r \ n" + NameTxtBx.Text +"\ r \ n"+ idcount.ToString();
PatNo.Text = " ;
NameTxtBx.Text = " ;
ToTxtBx0.Text = " ;
DropDownList1.SelectedIndex = -1;
RadioButtonList2.SelectedIndex = -1;
}
捕获
{
消息(" ,此);
}
}
}
捕获
{
消息(" ,受保护的 无效 DropDownList1_DataBound(对象发件人,EventArgs e)
{
DropDownList1.Items.Insert( 0 ," );
}
}
}< big> </ big >
解决方案
尝试通过源代码进行调试,以找出错误是在sp中还是在此处的代码中.
查看如何使用SP:
MSDN:HOW TO:使用Visual C#.NET在ASP.NET中调用SQL Server存储过程 [ MSDN:HOW TO:使用ADO.NET和Visual C#.NET调用参数化存储过程 [ ADO.NET:使用存储过程 [ MSDN:创建过程(Transact-SQL) [ namespace WebApplication1 { public partial class Trans : System.Web.UI.Page { SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["con"].ToString()); protected void Page_Load(object sender, EventArgs e) { } public static void Message(String message, Control cntrl) { ScriptManager.RegisterStartupScript(cntrl, cntrl.GetType(), "alert" , "alert('" + message + "');", true); } protected void Button1_Click(object sender, EventArgs e) { if (PatID_NO.Text != "") { SIDC a = new SIDC(); int n; n = a.valid_re_int(PatID_NO.Text); if (n > 3) { Message("Error as well as make sure identification number", this); return; } else PatID_NO.Focus(); } else PatID_NO.Focus(); try { if (NameTxtBx.Text == "" || ToTxtBx0.Text == "" || DropDownList1.SelectedIndex == 0 || RadioButtonList2.SelectedIndex == -1 || (PatNo.Text == "" && PatID_NO.Text == "") || (Convert.ToUInt64(PatNo.Text) <= 0) || (Convert.ToUInt64(PatNo.Text) > 200000000)) { Message("Error: Please make sure that all fields are entered correctly", this); return; } else { try { string Patient_name = NameTxtBx.Text, Export_TO = ToTxtBx0.Text, repType = RadioButtonList2.SelectedValue; ulong PatNoVal = Convert.ToUInt64(PatNo.Text); DateTime today = Convert.ToDateTime(DateTime.Now.ToShortDateString()); int?idcount = -1; int? replay_To_type = Int16.Parse(DropDownList1.SelectedValue); MembershipUser userid = Membership.GetUser(); //Message("Block 1", this); try { TransDataContext db = new TransDataContext(); try { var q = db.Transaction(Patient_name, Export_TO, replay_To_type, repType, PatNoVal,idcount); } catch { Message("block 3:There is an error in the entry form required, please contact the Department of Computer", this); } } catch { Message("block 2: ERROR CONTACT YOUR SYSTEM ADMINISTRATOR", this); } //Message("The transaction number " + idcount.ToString(), this); ClientScript.RegisterStartupScript(this.GetType(), "Message", "alert('Your ID is:" + idcount + "');", true); // TextBox1.Text = "Transaction number references" + "\r\n" + NameTxtBx.Text + "\r\n" + idcount.ToString(); PatNo.Text = ""; NameTxtBx.Text = ""; ToTxtBx0.Text = ""; DropDownList1.SelectedIndex = -1; RadioButtonList2.SelectedIndex = -1; } catch { Message("ERROR : ERROR 20", this); } } } catch { Message("Error: Make sure you enter the data correctly ", this); } } protected void DropDownList1_DataBound(object sender, EventArgs e) { DropDownList1.Items.Insert(0, "--Select One--"); } } }<big></big>解决方案Try debugging through the source code to figure out if the error is in the sp or in the code here itself.
Look here on how to use SP:
MSDN: HOW TO: Call SQL Server Stored Procedures in ASP.NET by Using Visual C# .NET[^]
MSDN: HOW TO: Call a Parameterized Stored Procedure by Using ADO.NET and Visual C# .NET[^]
ADO.NET : Using Stored Procedures[^]
In case issue with SP:
MSDN: CREATE PROCEDURE (Transact-SQL)[^]
这篇关于无法使用存储过程在SQl中插入值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文