Click here to Skip to main content
15,894,343 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
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
Posted
Comments
Sergey Alexandrovich Kryukov 21-Nov-11 0:46am    
For goodness sake, what an array? what loop?!
--SA
koolprasad2003 21-Nov-11 0:48am    
What you want exactly ? why you want to use Loop for inseration ?

 
Share this answer
 
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);
}
 
Share this answer
 
Following Code will Help you.

XML
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 %>"


            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!


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

Thanks
Yogesh
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900