<form id="formReceipt" action="wedding.ashx" method="post">
<div>
<label>1.您的姓名</label>
<input type="" id="reName"/>
</div>
<div class="margin-top-5">
<label>2.您的电话</label>
<input type="" id="reTel"/>
</div>
<input type="submit" value="发送"/>
<form />
这是请问下ashx这边的代码该怎么写,才能把数据提交到数据库
下面该怎么写啊
public void ProcessRequest (HttpContext context) {
context.Response.ContentType = "text/plain";
string GroomName = context.Request.Form["reName"];
string Mobile=context.Request.Form["reTel"];
}
这是webconfig连接到的sqlserver数据库
请问下,这么写没错吧
<connectionStrings>
<add name="ApplicationServices" connectionString="Data Source=211.149.217.187,15000;Initial Catalog=tab;User ID=s a;Password=tonsu168!@#"
providerName="System.Data.SqlClient" />
</connectionStrings>
30 个解决方案
#1
..难道不是用简单的SQL语句????INSERT INTO XXXXXXXXXXXXXXXXXXXXXX
#2
查下ado.net……
#3
我就是想知道 sql语句写在哪儿。。请问就直接写在这个方法下面么
public void ProcessRequest (HttpContext context) {
context.Response.ContentType = "text/plain";
string GroomName = context.Request.Form["reName"];
string Mobile=context.Request.Form["reTel"];
INSERT INTO XXXXXXXXXXXXXXXXXXXXXX
}
#4
using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString))
{
conn.Open();
using (SqlCommand command = new SqlCommand("insert into ....", conn))
{
command.ExecuteNonQuery();
}
conn.Close();
}
{
conn.Open();
using (SqlCommand command = new SqlCommand("insert into ....", conn))
{
command.ExecuteNonQuery();
}
conn.Close();
}
#5
没用过form表单,也没用过,ashx文件,我就是想知道sql语句写在哪儿。。
请问下是直接写在ashx文件下的这个方法中么
public void ProcessRequest (HttpContext context) {
context.Response.ContentType = "text/plain";
string GroomName = context.Request.Form["reName"];
string Mobile=context.Request.Form["reTel"];
INSERT INTO XXXXXXXXXXXXXXXXXXXXXX
}
#6
请问下这段代码写在哪儿啊,这个方法中么
public void ProcessRequest (HttpContext context) {
context.Response.ContentType = "text/plain";
string GroomName = context.Request.Form["reName"];
string Mobile=context.Request.Form["reTel"];
}
#7
把4楼的接在你的代码下面就好了啊
#8
补充下 是你的方法里面的下面
#9
补充下 是你的方法里面的下面
public void ProcessRequest (HttpContext context) {
context.Response.ContentType = "text/plain";
string GroomName = context.Request.Form["reName"];
string Mobile=context.Request.Form["reTel"];
using (SqlConnection conn = new SqlConnection())
{
conn.Open();
using (SqlCommand command = new SqlCommand("insert Sys_Wedding(GroomName,BrideName,Mobile) values('GroomName','Archer',Mobile)", conn))
{
command.ExecuteNonQuery();
}
conn.Close();
}
}
这样么
#10
补充下 是你的方法里面的下面
public void ProcessRequest (HttpContext context) {
context.Response.ContentType = "text/plain";
string GroomName = context.Request.Form["reName"];
string Mobile=context.Request.Form["reTel"];
using (SqlConnection conn = new SqlConnection())
{
conn.Open();
using (SqlCommand command = new SqlCommand("insert Sys_Wedding(GroomName,BrideName,Mobile) values('GroomName','Archer',Mobile)", conn))
{
command.ExecuteNonQuery();
}
conn.Close();
}
}
这样么
#11
对的
补充下 是你的方法里面的下面
public void ProcessRequest (HttpContext context) {
context.Response.ContentType = "text/plain";
string GroomName = context.Request.Form["reName"];
string Mobile=context.Request.Form["reTel"];
using (SqlConnection conn = new SqlConnection())
{
conn.Open();
using (SqlCommand command = new SqlCommand("insert Sys_Wedding(GroomName,BrideName,Mobile) values('GroomName','Archer',Mobile)", conn))
{
command.ExecuteNonQuery();
}
conn.Close();
}
}
这样么
请问下,我断点调了下,为什么GroomName 这个值是null,这样取不到么
#12
补充下 是你的方法里面的下面
这是form表单的代码
<form id="formRemind" method="post" action="wedding.ashx">
<div id="remindNameAndTel" class="absolute color-earth margin-top-15" style="width:75%">
<div>
姓名:<input type="" id="remindName" class="width-per60"/>
</div>
<div class="margin-top-15">
手机:<input type="" id="remindTel" class="width-per60"/>
</div>
</div>
<div id="send" class="width-per30 absolute">
<input type="submit" value="发送" style="background:#714718"/>
</div>
</form>
这是ashx的代码
public void ProcessRequest (HttpContext context) {
context.Response.ContentType = "text/plain";
//string GroomName = context.Request.Form["reName"];
//string Mobile = context.Request.Form["reTel"];
string remindName = context.Request.QueryString["remindName"];
string Mobile = context.Request.Params["remindTel"];
using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString))
{
conn.Open();
using (SqlCommand command = new SqlCommand("insert Sys_Wedding(GroomName,BrideName,Mobile) values('GroomName','Archer',Mobile)", conn))
{
command.ExecuteNonQuery();
}
conn.Close();
}
}
为什么取的值为null啊
#13
试试context.Request["reName"];
#14
<form id="formReceipt" action="wedding.ashx" method="post">
<div>
<label>1.您的姓名</label>
<input type=" text" id="reName"/>
</div>
<div class="margin-top-5">
<label>2.您的电话</label>
<input type=" text" id="reTel"/>
</div>
<input type="submit" value="发送"/>
</form>
<div>
<label>1.您的姓名</label>
<input type=" text" id="reName"/>
</div>
<div class="margin-top-5">
<label>2.您的电话</label>
<input type=" text" id="reTel"/>
</div>
<input type="submit" value="发送"/>
</form>
#15
<form id="formReceipt" action="wedding.ashx" method="post">
<div>
<label>1.您的姓名</label>
<input type=" text" id="reName"/>
</div>
<div class="margin-top-5">
<label>2.您的电话</label>
<input type=" text" id="reTel"/>
</div>
<input type="submit" value="发送"/>
断点调了下,还是值还是为null
#16
Request.Form["XXX"];其中的XXX是HTML标签的name 不是id
另外 最好不要把SQL写在Handler里面
另外 最好不要把SQL写在Handler里面
#17
Request.Form["XXX"];其中的XXX是HTML标签的name 不是id
另外 最好不要把SQL写在Handler里面
嗯,就是没有Name,那请问sql应该写在哪儿啊,还有,为什么表单提交后页面就一片空白了。。
#18
因为你提交后没有跳转页面,如果用ajax提交就可以留着当前页面
#19
因为你提交后没有跳转页面,如果用ajax提交就可以留着当前页面
用ajax提交后,样式就乱了。。
#20
对他说:快到碗里来
#21
#22
#23
连接数据库,除了你要有数据表以外,还有连接的语言需要,要上传到数据库的话,php是可以的。具体的你可以百度一下。
#24
获取表单内容,然后连接数据库,然后 插 入。没了
#25
建议楼主先看书或看视频学习吧!挺简单的
#26
#27
#28
建议楼主学习学习JDBC,或者MyBatis
#29
#30
#1
..难道不是用简单的SQL语句????INSERT INTO XXXXXXXXXXXXXXXXXXXXXX
#2
查下ado.net……
#3
..难道不是用简单的SQL语句????INSERT INTO XXXXXXXXXXXXXXXXXXXXXX
我就是想知道 sql语句写在哪儿。。请问就直接写在这个方法下面么
public void ProcessRequest (HttpContext context) {
context.Response.ContentType = "text/plain";
string GroomName = context.Request.Form["reName"];
string Mobile=context.Request.Form["reTel"];
INSERT INTO XXXXXXXXXXXXXXXXXXXXXX
}
#4
using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString))
{
conn.Open();
using (SqlCommand command = new SqlCommand("insert into ....", conn))
{
command.ExecuteNonQuery();
}
conn.Close();
}
{
conn.Open();
using (SqlCommand command = new SqlCommand("insert into ....", conn))
{
command.ExecuteNonQuery();
}
conn.Close();
}
#5
查下ado.net……
没用过form表单,也没用过,ashx文件,我就是想知道sql语句写在哪儿。。
请问下是直接写在ashx文件下的这个方法中么
public void ProcessRequest (HttpContext context) {
context.Response.ContentType = "text/plain";
string GroomName = context.Request.Form["reName"];
string Mobile=context.Request.Form["reTel"];
INSERT INTO XXXXXXXXXXXXXXXXXXXXXX
}
#6
using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString))
{
conn.Open();
using (SqlCommand command = new SqlCommand("insert into ....", conn))
{
command.ExecuteNonQuery();
}
conn.Close();
}
请问下这段代码写在哪儿啊,这个方法中么
public void ProcessRequest (HttpContext context) {
context.Response.ContentType = "text/plain";
string GroomName = context.Request.Form["reName"];
string Mobile=context.Request.Form["reTel"];
}
#7
using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString))
{
conn.Open();
using (SqlCommand command = new SqlCommand("insert into ....", conn))
{
command.ExecuteNonQuery();
}
conn.Close();
}
请问下这段代码写在哪儿啊,这个方法中么
public void ProcessRequest (HttpContext context) {
context.Response.ContentType = "text/plain";
string GroomName = context.Request.Form["reName"];
string Mobile=context.Request.Form["reTel"];
}
把4楼的接在你的代码下面就好了啊
#8
补充下 是你的方法里面的下面
#9
补充下 是你的方法里面的下面
public void ProcessRequest (HttpContext context) {
context.Response.ContentType = "text/plain";
string GroomName = context.Request.Form["reName"];
string Mobile=context.Request.Form["reTel"];
using (SqlConnection conn = new SqlConnection())
{
conn.Open();
using (SqlCommand command = new SqlCommand("insert Sys_Wedding(GroomName,BrideName,Mobile) values('GroomName','Archer',Mobile)", conn))
{
command.ExecuteNonQuery();
}
conn.Close();
}
}
这样么
#10
补充下 是你的方法里面的下面
public void ProcessRequest (HttpContext context) {
context.Response.ContentType = "text/plain";
string GroomName = context.Request.Form["reName"];
string Mobile=context.Request.Form["reTel"];
using (SqlConnection conn = new SqlConnection())
{
conn.Open();
using (SqlCommand command = new SqlCommand("insert Sys_Wedding(GroomName,BrideName,Mobile) values('GroomName','Archer',Mobile)", conn))
{
command.ExecuteNonQuery();
}
conn.Close();
}
}
这样么
#11
对的
补充下 是你的方法里面的下面
public void ProcessRequest (HttpContext context) {
context.Response.ContentType = "text/plain";
string GroomName = context.Request.Form["reName"];
string Mobile=context.Request.Form["reTel"];
using (SqlConnection conn = new SqlConnection())
{
conn.Open();
using (SqlCommand command = new SqlCommand("insert Sys_Wedding(GroomName,BrideName,Mobile) values('GroomName','Archer',Mobile)", conn))
{
command.ExecuteNonQuery();
}
conn.Close();
}
}
这样么
请问下,我断点调了下,为什么GroomName 这个值是null,这样取不到么
#12
补充下 是你的方法里面的下面
这是form表单的代码
<form id="formRemind" method="post" action="wedding.ashx">
<div id="remindNameAndTel" class="absolute color-earth margin-top-15" style="width:75%">
<div>
姓名:<input type="" id="remindName" class="width-per60"/>
</div>
<div class="margin-top-15">
手机:<input type="" id="remindTel" class="width-per60"/>
</div>
</div>
<div id="send" class="width-per30 absolute">
<input type="submit" value="发送" style="background:#714718"/>
</div>
</form>
这是ashx的代码
public void ProcessRequest (HttpContext context) {
context.Response.ContentType = "text/plain";
//string GroomName = context.Request.Form["reName"];
//string Mobile = context.Request.Form["reTel"];
string remindName = context.Request.QueryString["remindName"];
string Mobile = context.Request.Params["remindTel"];
using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString))
{
conn.Open();
using (SqlCommand command = new SqlCommand("insert Sys_Wedding(GroomName,BrideName,Mobile) values('GroomName','Archer',Mobile)", conn))
{
command.ExecuteNonQuery();
}
conn.Close();
}
}
为什么取的值为null啊
#13
试试context.Request["reName"];
#14
<form id="formReceipt" action="wedding.ashx" method="post">
<div>
<label>1.您的姓名</label>
<input type=" text" id="reName"/>
</div>
<div class="margin-top-5">
<label>2.您的电话</label>
<input type=" text" id="reTel"/>
</div>
<input type="submit" value="发送"/>
</form>
<div>
<label>1.您的姓名</label>
<input type=" text" id="reName"/>
</div>
<div class="margin-top-5">
<label>2.您的电话</label>
<input type=" text" id="reTel"/>
</div>
<input type="submit" value="发送"/>
</form>
#15
<form id="formReceipt" action="wedding.ashx" method="post">
<div>
<label>1.您的姓名</label>
<input type=" text" id="reName"/>
</div>
<div class="margin-top-5">
<label>2.您的电话</label>
<input type=" text" id="reTel"/>
</div>
<input type="submit" value="发送"/>
断点调了下,还是值还是为null
#16
Request.Form["XXX"];其中的XXX是HTML标签的name 不是id
另外 最好不要把SQL写在Handler里面
另外 最好不要把SQL写在Handler里面
#17
Request.Form["XXX"];其中的XXX是HTML标签的name 不是id
另外 最好不要把SQL写在Handler里面
嗯,就是没有Name,那请问sql应该写在哪儿啊,还有,为什么表单提交后页面就一片空白了。。
#18
因为你提交后没有跳转页面,如果用ajax提交就可以留着当前页面
#19
因为你提交后没有跳转页面,如果用ajax提交就可以留着当前页面
用ajax提交后,样式就乱了。。
#20
对他说:快到碗里来
#21
#22
#23
连接数据库,除了你要有数据表以外,还有连接的语言需要,要上传到数据库的话,php是可以的。具体的你可以百度一下。
#24
获取表单内容,然后连接数据库,然后 插 入。没了
#25
建议楼主先看书或看视频学习吧!挺简单的
#26
#27
#28
建议楼主学习学习JDBC,或者MyBatis