如何在数组的帮助下将数据从文本框插入asp.net中的数据库 [英] how to insert data from textbox to database in asp.net with help of array

查看:37
本文介绍了如何在数组的帮助下将数据从文本框插入asp.net中的数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨 我是shailendra singh.我是asp.net(C#)中的新手.如何在数组或任何Loop帮助的帮助下如何将文本框中的数据插入asp.net中的数据库. />

感谢您的进步




Shailendra singh

Hi I am shailendra singh .I am new in asp.net(C#).How to insert data from textbox to database in asp.net with help of array or any Loop help .How can possible .Please Give step by step process.


Thanks for Advance




Shailendra singh

推荐答案

以下代码将为您提供帮助.

Following Code will Help you.

textbox databinding to a Sql Database.
Nov 06, 2006 07:24 PM | LINK

Not sure if anyone else is banging their head or not.

However I here is how to databind a textbox to a SQL Database using a sqldata control.

Here is the code behind



using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        SqlDataSource1.InsertParameters["Title"].DefaultValue = txtTitle.Text.ToString();
        SqlDataSource1.InsertParameters["Body"].DefaultValue = txtBody2.Text.ToString();
        SqlDataSource1.InsertParameters["StartDate"].DefaultValue = MyDateStartTB1.Text.ToString();
        SqlDataSource1.InsertParameters["EndDate"].DefaultValue = MyDateEndTB2.Text.ToString();
        SqlDataSource1.Insert();
    }
}







 the Source:


<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%


ConnectionStrings:local %> " span> =" 从[tblPageContent]删除[ID] = @ID" InsertCommand INSERT INTO [tblPageContent]([StartDate],[EndDate],[标题],[正文])值(@ StartDate,@ EndDate,@ Title,@ Body)" span> =" 选择*来自[tblPageContent]" UpdateCommand =" < DeleteParameters > < asp:Parameter 名称 =" 类型 Int32 " / < /DeleteParameters > < UpdateParameters > < asp:Parameter 名称 =" 类型 DateTime " / < asp:Parameter 名称 =" 类型 DateTime " / < asp:Parameter 名称 =" 类型 字符串" / < asp:Parameter 名称 =" 类型 字符串" / < asp:Parameter 名称 =" 类型 Int32 " / < /UpdateParameters > < InsertParameters > < asp:Parameter 名称 =" 类型 DateTime " / < asp:Parameter 名称 =" 类型 DateTime " / < asp:Parameter 名称 =" 类型 字符串" / < asp:Parameter 名称 =" 类型 字符串" / < /InsertParameters > < /asp:SqlDataSource > 不是太难. 参考: http://www.aspnettutorials.com/tutorials/database/connect-sql-datasource-csharp.aspx 享受吧!
ConnectionStrings:local %>" DeleteCommand="DELETE FROM [tblPageContent] WHERE [ID] = @ID" InsertCommand="INSERT INTO [tblPageContent] ([StartDate], [EndDate], [Title], [Body]) VALUES (@StartDate, @EndDate, @Title, @Body)" SelectCommand="SELECT * FROM [tblPageContent]" UpdateCommand="UPDATE [tblPageContent] SET [StartDate] = @StartDate, [EndDate] = @EndDate, [Title] = @Title, [Body] = @Body WHERE [ID] = @ID"> <DeleteParameters> <asp:Parameter Name="ID" Type="Int32" /> </DeleteParameters> <UpdateParameters> <asp:Parameter Name="StartDate" Type="DateTime" /> <asp:Parameter Name="EndDate" Type="DateTime" /> <asp:Parameter Name="Title" Type="String" /> <asp:Parameter Name="Body" Type="String" /> <asp:Parameter Name="ID" Type="Int32" /> </UpdateParameters> <InsertParameters> <asp:Parameter Name="StartDate" Type="DateTime" /> <asp:Parameter Name="EndDate" Type="DateTime" /> <asp:Parameter Name="Title" Type="String" /> <asp:Parameter Name="Body" Type="String" /> </InsertParameters> </asp:SqlDataSource> Not too hard. Reference: http://www.aspnettutorials.com/tutorials/database/connect-sql-datasource-csharp.aspx Enjoy!



它的基本代码可根据您的要求进行模制.

谢谢
Yogesh



its basic code you can mold it as per your requirments.

Thanks
Yogesh


String [] Arr = new String [] {"Aman","Puneet","Rohit"};
for(int i = 0; i< Arr.Length; i ++)
{
Textbox1.Text = Arr [i];

插入表名称值((" + Arr [i] +'',con);
}
String[] Arr =new String[]{"Aman","Puneet","Rohit"};
for(int i=0; i<Arr.Length;i++)
{
Textbox1.Text=Arr[i];
or
Insert Into TableNames Values(''"+Arr[i]+"'',con);
}


这篇关于如何在数组的帮助下将数据从文本框插入asp.net中的数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆