【发布时间】:2013-10-16 19:21:36
【问题描述】:
我正在从一个 aspx Web 应用程序填充一个数据库。
一切正常,除了我使用多个页面让用户将他们的数据填写到数据库中。
所以,我在一个 class.cs 文件中得到了这个方法:
public class Botones
{
public void SaveCVInfo2(string varOne,string varTwo, string varThree)
{
using (ConexionGeneralDataContext db = new ConexionGeneralDataContext())
{
Usuario_Web columna = new Usuario_Web();
//Add new values to each fields
columna.Nombre = varOne;
columna.Apellido = varTwo;
columna.Em_solicitado = varThree;
//and the rest where the textboxes would have been
//Insert the new Customer object
db.Usuario_Web.InsertOnSubmit(columna);
//Sumbit changes to the database
db.SubmitChanges();
}
}
}
这只是文件的一部分,它有更多的列,但不会改变示例。
但是,我添加了另一个 class.cs 文件,以便从第二页中的按钮引用它的方法。就像我之前在这篇文章中发布的一样:
public class Botones2
{
public void SaveCVInfo3(string varOne, string varTwo, string varThree, string varFour, string varFive, string varSix, string varSeven,
string varEight, string varNine, string varTen, string varEleven, string varTwelve, string varThirteen, string varFourteen, string varFifteen)
{
using (ConexionGeneralDataContext db = new ConexionGeneralDataContext())
{
Usuario_Web columna = new Usuario_Web();
//Insert the new Customer object
columna.Estatus = 1;
columna.nombre_esposo = varOne;
columna.profe_compa = varTwo;
columna.emp_compa = varThree;
columna.cargo_actual_compa = varFour;
columna.Hijos = varFive;
columna.Edades_hijos = varSix;
columna.persona_depende_compa = varSeven;
columna.afinidades = varEight;
columna.Edades_depende = varNine;
columna.nom_padre = varTen;
columna.profesion_padre = varEleven;
columna.tel_padre = varTwelve;
columna.nom_madre = varThirteen;
columna.profesion_madre = varFourteen;
columna.tel_madre = varFifteen;
db.Usuario_Web.InsertOnSubmit(columna);
//Sumbit changes to the database
db.SubmitChanges();
}
}
}
您可以看到我在数据库中填写了更多列,在同一张表中,问题是,当我从第二页向 sql 服务器提交数据时,它只是创建了一个新的 Usuario_web 而没有我在第一堂课中引用的列。
我需要的是bind 以某种方式已经从第一页发送的数据。所以第一个类与所有其他类相关联,并且列填充在同一行中。
如果有人知道如何处理这种情况,请告诉我。
编辑
这就是我从 asp 按钮调用方法的方式:
protected void Button1_Click(object sender, EventArgs e)
{
Botones botones = new Botones();
botones.SaveCVInfo2(nombre.Text, Apellidos.Text, EmpleoS.Text);
}
并保存CVInfo3:
protected void Button1_Click(object sender, EventArgs e)
{
Botones2 botones2 = new Botones2();
botones2.SaveCVInfo3(nombre_compa.Text, Profesion_compa.Text, Emp_trabaja.Text, Cargo_compa.Text, RadioButtonList8.SelectedItem.Text, edades_sons.Text, num_depende.Text, Afinidad.Text, Edad_compa.Text, nom_padre.Text, profesion_compa_padre.Text, Tel_compa.Text, nom_madre.Text, profesion_compa_madre.Text, Tel_compa_madre.Text);
Response.Redirect("Envia3.aspx");
}
【问题讨论】:
-
你能说明你是如何从页面调用 SaveCVInfo2 和 SaveCVInfo3 的吗?
标签: c# asp.net sql-server linq visual-studio