내 과제 중 하나는 사용자가 데이터를 입력 할 때 데이터베이스에 쓰는 양식을 만드는 것입니다. 나는 지금까지 얻었지만 몇 가지 오류가 발생합니다. 이것은 내가 지금까지 가지고있는 것이다.asp.net 가입 양식 데이터베이스에 쓰기
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Configuration;
using System.Data.SqlClient;
namespace Registration
{
public class Registration
{
#region Declaration
public string Name { get; set; }
public int Age { get; set; }
public string Sex { get; set; }
public string Address { get; set; }
public string Email { get; set; }
public int Phone { get; set; }
#endregion
}
}
내가 갖는 오류는 이름 등록이 현재 컨텍스트
을 존재하지 않는나는 또한 내가 별도의 파일로 만든 클래스가
입니다
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data.SqlClient; using System.Configuration; using System.Data; public partial class subscribe_Registration : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) { reg.Name = txtName.Text; reg.Age = txtAge.Text; reg.Sex = txtSex.Text; reg.Address = txtAddress.Text; reg.Email = txtEmail.Text; reg.Phone = txtPhone.Text; reg.InsertRegistration(); phSuccess.Visible = true; } #region Methods public void InsertRegistration() { SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["Database"].ConnectionString); SqlCommand cmd = new SqlCommand("spRegistrationInsert", conn); cmd.CommandType = CommandType.StoredProcedure; SqlParameter parameterName = new SqlParameter("@Name", SqlDbType.VarChar, 50); SqlParameter parameterAge = new SqlParameter("@Age", SqlDbType.VarChar, 50); SqlParameter parameterSex = new SqlParameter("@Sex", SqlDbType.VarChar, 50); SqlParameter parameterAddress = new SqlParameter("@Address", SqlDbType.VarChar, 50); SqlParameter parameterEmail = new SqlParameter("@Email", SqlDbType.VarChar, 100); SqlParameter parameterPhone = new SqlParameter("@Phone", SqlDbType.VarChar, 100); parameterName.Value = txtName; parameterAge.Value = txtAge; parameterEmail.Value = txtSex; parameterAddress.Value = txtAddress; parameterEmail.Value = txtEmail; parameterPhone.Value = txtPhone; cmd.Parameters.Add(parameterName); cmd.Parameters.Add(parameterAge); cmd.Parameters.Add(parameterSex); cmd.Parameters.Add(parameterAddress); cmd.Parameters.Add(parameterEmail); cmd.Parameters.Add(parameterPhone); try { conn.Open(); cmd.ExecuteNonQuery(); } catch (Exception ex) { throw new Exception(ex.ToString()); } finally { cmd.Dispose(); conn.Close(); } } } #endregion namespace Registration { public partial class Registration : System.Web.UI.Page { #region Declarations Registration reg = new Registration(); #endregion } }
누구나 내가 잘못 가고있는 부분을 알려줄 수 있습니까?
빠른 응답을 주셔서 감사합니다. 지금은 '등록은 네임 스페이스이지만 형식처럼 사용됩니다'라고 덧붙였습니다. – user6725507
@Leopard는 'Registration.Registration reg = new Registration.Registration();' 네임 스페이스에 대해서도 같은 이름이 있습니다 .. – SilentCoder
Codelahiru를 사용하는 것 같았습니다. 너희들은 정말 도움이된다. 나는 다른 사람들을 돕기 위해 돌아올 수있을 때 그렇게 많이 감사한다. – user6725507