单击提交按钮时,数据应存储在数据库中. [英] When submit button is clicked, the data should be stored in a Database.
本文介绍了单击提交按钮时,数据应存储在数据库中.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
接受以下形式的表格:
时的学生姓名,电子邮件和出生日期(日历)
单击提交按钮应将其存储在Sql服务器上.请帮助我..
a form that accepts: Student Name , Email and Date of Birth (Calendar) when the
submit button clicked It should be stored on Sql sever database.please help me..
推荐答案
使用以下代码:
表格创建:
/*用于创建表的SQL查询*/
创建表tblUserDetails
(
名称VARCHAR(30),
EmailID VARCHAR(40),
DateOfBirth VARCHAR(25)
)
C#代码:
SqlConnection con =新的SqlConnection("ConfiguraionManager.ConnectionString [" con].ConnectionString");
con.Open();
SqlCommand cmd = new SqlCommand(插入tblUserDetailsvalues(" + txtName.Text.Trim()+"," + txtEmailID.Text.Trim()+"," + txtDateOfBirth.Text .Trim()+'')",con);
int intResult = cmd.ExecuteNonExecuteQuery();
if(intResult> = 1)
{
ScriptManager.RegisterStartUpScript(this,this.GetType(),消息",警报("成功保存)",true);
}
其他
{
ScriptManager.RegisterStartUpScript(this,this.GetType(),"Message","alert("无法保存重试)",true);
}
Use following code:
Table Creation :
/*SQL Query to create table*/
CREATE TABLE tblUserDetails
(
Name VARCHAR(30),
EmailID VARCHAR(40),
DateOfBirth VARCHAR(25)
)
C# Code :
SqlConnection con=new SqlConnection("ConfiguraionManager.ConnectionString["con"].ConnectionString");
con.Open();
SqlCommand cmd=new SqlCommand("insert into tblUserDetailsvalues(''"+txtName.Text.Trim()+"'',''"+txtEmailID.Text.Trim()+"'',''"+txtDateOfBirth.Text.Trim()+"'')",con);
int intResult=cmd.ExecuteNonExecuteQuery();
if(intResult>=1)
{
ScriptManager.RegisterStartUpScript(this,this.GetType(),"Message","alert(''Saved Successfully'')",true);
}
else
{
ScriptManager.RegisterStartUpScript(this,this.GetType(),"Message","alert(''Unable to save try again'')",true);
}
这篇关于单击提交按钮时,数据应存储在数据库中.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文