1.- Hice una nuevo proyecto con una pagina Default.aspx y en ella una pequeña tabla con dos campos TextBox, uno para el nombre y otro para el apellido, no estoy seguro si tiene que llevar un form para enviar los datos. algo como "<form action="archivo.aspx.cs" metod="post">" aqui les pego el código:
Código:
En el botón Button1 le asigne un evento que se llama Conexion que está en el archivo Default.aspx.cs aquí el código del archivo:<h2>GUARDAR DATOS EN SQL CON ASPX</h2>
<table style="width: 100%;">
<tr>
<td>Nombre:</td>
<td><input id="Text1" type="text" /></td>
</tr>
<tr>
<td>Apellidos:</td>
<td><input id="Text2" type="text" /></td>
</tr>
<tr>
<td>
</td>
<td>
<asp:Button ID="Button1" runat="server" Text="Guardar" onclick="Conexion" />
</td>
</tr>
</table>
Código:
En este archivo se encuentra mi conexión a mi base de datos.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;
namespace ACADES
{
public partial class _Default : System.Web.UI.Page
{
protected void Conexion(object sender, EventArgs e)
{
SqlCommand cm = new SqlCommand();
SqlConnection cn = new SqlConnection("Data Source=INTELIGENCIAART\\SQLEXPRESS;Initial Catalog=ACADES;Integrated Security=True;");
cm.Connection = cn;
cm.CommandType = CommandType.Text;
cm.CommandText = "INSERT INTO Alumnos(persona,nombre) values(@nombre,@persona)";
SqlParameter par_nombre = cm.Parameters.Add("@nombre", SqlDbType.NChar);
SqlParameter par_apellido = cm.Parameters.Add("@persona", SqlDbType.NChar);
par_nombre.Value = "Text1.Text";
par_apellido.Value = "Text2.Text";
cn.Open();
cm.ExecuteNonQuery();
cn.Close();
}
}
}
la pregunta en si es ¿Cómo paso el valor de los textbox cituados en el primer archivo Default.aspx al archivo Default.aspx.cs?
en estas dos lineas el "Text1.Text" y "Text2.Text" representarian el valor correspondiente.
par_nombre.Value = "Text1.Text";
par_apellido.Value = "Text2.Text";
Muchas Gracias.



