为什么在cmd.Parameters.AddWithValue("@ rtype",sc1)中出错?我也想在这里使用更新面板 [英] Why error in cmd.Parameters.AddWithValue("@rtype",sc1); and also i want to use update panel here
本文介绍了为什么在cmd.Parameters.AddWithValue("@ rtype",sc1)中出错?我也想在这里使用更新面板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
HTML部分为
cmd.Parameters.AddWithValue("@ rtype",sc1);中的错误;
Html Part is
error in cmd.Parameters.AddWithValue("@rtype",sc1);
<form id="form1" runat="server">
<div>
<table align="center" class="style1">
<tr>
<td class="style8">
</td>
<td class="style6">
</td>
<td class="style11">
</td>
<td class="style14">
</td>
<td>
</td>
</tr>
<tr>
<td class="style9">
</td>
<td class="style4">
Your Email ID</td>
<td class="style12">
<asp:TextBox ID="txtEmail" runat="server"></asp:TextBox>
</td>
<td class="style15">
</td>
<td class="style3">
</td>
</tr>
<tr>
<td class="style8">
</td>
<td class="style6">
First Name</td>
<td class="style11">
<asp:TextBox ID="txtFname" runat="server"></asp:TextBox>
</td>
<td class="style14">
</td>
<td>
</td>
</tr>
<tr>
<td class="style8">
</td>
<td class="style6">
Last Name</td>
<td class="style11">
<asp:TextBox ID="txtLname" runat="server"></asp:TextBox>
</td>
<td class="style14">
</td>
<td>
</td>
</tr>
<tr>
<td class="style10">
</td>
<td class="style7">
Date of Birth</td>
<td class="style13">
<asp:TextBox ID="txtDob" runat="server"></asp:TextBox>
</td>
<td class="style16">
</td>
<td class="style5">
</td>
</tr>
<tr>
<td class="style8">
</td>
<td class="style6">
Contact Number</td>
<td class="style11">
<asp:TextBox ID="txtCno" runat="server"></asp:TextBox>
</td>
<td class="style14">
</td>
<td>
</td>
</tr>
<tr>
<td class="style8">
</td>
<td class="style2" colspan="2">
<asp:RadioButton ID="rbStudent" runat="server" Text="Student"
GroupName="Type" AutoPostBack="True"
oncheckedchanged="RadioButton1_CheckedChanged" />
<br />
<asp:RadioButton ID="rbPFaculty" runat="server" Text="Private Faculty"
oncheckedchanged="RadioButton2_CheckedChanged" GroupName="Type"
AutoPostBack="True" />
<br />
<asp:RadioButton ID="rbSFaculty" runat="server" Text="SchoolFaculty"
GroupName="Type" />
</td>
<td class="style14">
</td>
<td>
</td>
</tr>
<tr>
<td class="style8">
</td>
<td class="style6">
Class</td>
<td class="style11">
<asp:DropDownList ID="ddClass" runat="server">
</asp:DropDownList>
</td>
<td class="style14">
</td>
<td>
</td>
</tr>
<tr>
<td class="style8">
</td>
<td class="style6">
School</td>
<td class="style11">
<asp:TextBox ID="txtSchool" runat="server"></asp:TextBox>
</td>
<td class="style14">
</td>
<td>
</td>
</tr>
<tr>
<td class="style8">
</td>
<td class="style6">
Board</td>
<td class="style11">
<asp:DropDownList ID="ddBoard" runat="server">
</asp:DropDownList>
</td>
<td class="style14">
</td>
<td>
</td>
</tr>
<tr>
<td class="style10">
</td>
<td class="style7">
City</td>
<td class="style13">
<asp:DropDownList ID="ddCity" runat="server">
</asp:DropDownList>
</td>
<td class="style16">
</td>
<td class="style5">
</td>
</tr>
<tr>
<td class="style8">
</td>
<td class="style6">
Pin Code</td>
<td class="style11">
<asp:TextBox ID="txtPCode" runat="server"></asp:TextBox>
</td>
<td class="style14">
</td>
<td>
</td>
</tr>
<tr>
<td class="style8">
</td>
<td class="style6">
State</td>
<td class="style11">
<asp:DropDownList ID="ddState" runat="server">
</asp:DropDownList>
</td>
<td class="style14">
</td>
<td>
</td>
</tr>
<tr>
<td class="style8">
</td>
<td class="style6" colspan="2">
<asp:CheckBox ID="CheckBox1" runat="server" Text="Term & Condition" />
</td>
<td class="style14" valign="middle">
Read Condition</td>
<td>
</td>
</tr>
<tr>
<td class="style8">
</td>
<td class="style6">
<asp:Button ID="Button1" runat="server" Text="Submit Details"
onclick="Button1_Click" />
</td>
<td class="style11">
<asp:Button ID="Button2" runat="server" Text="Refill all Details" />
</td>
<td class="style14">
</td>
<td>
</td>
</tr>
<tr>
<td class="style8">
</td>
<td class="style6">
</td>
<td class="style11">
</td>
<td class="style14">
</td>
<td>
</td>
</tr>
</table>
</div>
</form>
cs coding is
cs coding is
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
public partial class registration : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void RadioButton2_CheckedChanged(object sender, EventArgs e)
{
if (rbPFaculty.Checked == true)
{
ddClass.Enabled = true;
}
}
protected void RadioButton1_CheckedChanged(object sender, EventArgs e)
{
if (rbStudent.Checked == true)
{
ddClass.Enabled = false;
}
}
protected void Button1_Click(object sender, EventArgs e)
{
string sc1;
if (rbStudent.Checked == true)
{
sc1 = "Student";
}
if (rbPFaculty.Checked == true)
{
sc1 = "Private Faculty";
}
if (rbSFaculty.Checked == true)
{
sc1 = "School Faculty";
}
SqlConnection CON = new SqlConnection(System.Web.Configuration.WebConfigurationManager.ConnectionStrings["tuitionConnectionString"].ConnectionString);
SqlTransaction tr = null;
CON.Open();
tr = CON.BeginTransaction();
try
{
SqlCommand cmd = new SqlCommand("insert into registration (email,fname,lname,dob,cont,rtype,tclass,board,city,pcode,state) values (@email,@fname,@lname,@dob,@cont,@rtype,@tclass,@board,@city,@pcode,@state)");
cmd.Parameters.AddWithValue("@email", txtEmail.Text);
cmd.Parameters.AddWithValue("@fname", txtFname.Text);
cmd.Parameters.AddWithValue("@lname", txtLname.Text);
cmd.Parameters.AddWithValue("@dob", txtDob.Text);
cmd.Parameters.AddWithValue("@cont", txtCno.Text);
cmd.Parameters.AddWithValue("@rtype",sc1);
cmd.Parameters.AddWithValue("@tclass", ddClass.SelectedValue);
cmd.Parameters.AddWithValue("@board", txtFname.Text);
cmd.Parameters.AddWithValue("@city", txtFname.Text);
cmd.Parameters.AddWithValue("@pcode", txtFname.Text);
cmd.Parameters.AddWithValue("@state", txtFname.Text);
cmd.Connection = CON;
cmd.ExecuteNonQuery();
tr.Commit();
}
catch (Exception ex)
{
tr.Rollback();
}
finally
{
CON.Close();
}
}
}
推荐答案
You have not initialized sc1.
So if rbStudent and rbPFaculty and rbSFaculty are not checked then sc1 = null
I suspect you get the error when executing the query and that rtype is a not nullable field.
You have not initialized sc1.
So if rbStudent and rbPFaculty and rbSFaculty are not checked then sc1 = null
I suspect you get the error when executing the query and that rtype is a not nullable field.
这篇关于为什么在cmd.Parameters.AddWithValue("@ rtype",sc1)中出错?我也想在这里使用更新面板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文