我的代码中有一些问题;我没有解决它.请帮助我.........! [英] There are some problems on my code;i didn;t fix it.please help me.........!

查看:95
本文介绍了我的代码中有一些问题;我没有解决它.请帮助我.........!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (IsPostBack)
        {
            SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["RegistrationConnectionString"].ConnectionString);
            con.Open();
            string userinfo = "select count(*) from [Userdetails] where UserName='" + TextBoxUN.Text + "'";
            SqlCommand com = new SqlCommand(userinfo, con);
            int temp = Convert.ToInt32(com.ExecuteScalar().ToString());
            //int temp = (int)com.ExecuteScalar();
            if (temp == 1)
            {
                Response.Write("User already exists");
            }
            con.Close();


        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        try
            {
                //Guid guid = Guid.NewGuid();
                SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["RegistrationConnectionString"].ConnectionString);
                con.Open();
                string insertQuiry = "INSERT INTO [Userdetails] (Name,[UserName],[E-mail],Password,Address,[Contact Number],Birth,[Occupation],[Annual income],[Opening Ammount],Sex) values(@name,@Uname,@email,@password,@address,@cell_no,@birth,@occupation,@income,@ammount,@Sex)";
                SqlCommand com = new SqlCommand(insertQuiry, con);
                //com.Parameters.AddWithValue("@ID", guid.ToString());
                com.Parameters.AddWithValue("@name", TextBoxName.Text);
                com.Parameters.AddWithValue("@Uname", TextBoxUN.Text);
                com.Parameters.AddWithValue("@email", TextBoxemail.Text);
                com.Parameters.AddWithValue("@password", TextBoxP.Text);
                 com.Parameters.AddWithValue("@address", TextBoxaddress.Text);
                com.Parameters.AddWithValue("@cell_no", TextBoxCN.Text);
                com.Parameters.AddWithValue("@birth",TextBoxbirth.Text);
                 com.Parameters.AddWithValue("@occupation",TextBoxoccupation.Text);
             com.Parameters.AddWithValue("@income",TextBoxAI.Text);
             com.Parameters.AddWithValue("@ammount",Opening.SelectedItem.ToString());
             com.Parameters.AddWithValue("@Sex",Gender.SelectedItem.ToString());
                
               com.ExecuteNonQuery();
              
                  Response.Redirect("manger.aspx");
                  Response.Write("Registration is succesful");

                  con.Close();




              

               
            }
            catch (Exception excep)
            {

                Response.Write("Error:" + excep.ToString());
            }
           
           
        }

        }

推荐答案

第No行有错误. 54,正在保存的数据可能是字符串,数据库中的数据类型是数字,或者正在传递的日期格式无效

请检查相同的
There is an error at line no . 54, it may be that the data being saved is string and in data type in database is numeric or the format of date that is being passed is invalid

please check the same


这篇关于我的代码中有一些问题;我没有解决它.请帮助我.........!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆