Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET
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 20-Nov-11 18:44pm
Comments
SAKryukov at 21-Nov-11 0:46am
   
For goodness sake, what an array? what loop?!
--SA
koolprasad2003 at 21-Nov-11 0:48am
   
What you want exactly ? why you want to use Loop for inseration ?
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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

            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
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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);
}
  Permalink  

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 682
1 ChauhanAjay 135
2 Maciej Los 130
3 ChintanShukla 90
4 ashok rathod 90
0 Sergey Alexandrovich Kryukov 10,200
1 OriginalGriff 6,987
2 CPallini 5,850
3 George Jonsson 4,015
4 Gihan Liyanage 3,266


Advertise | Privacy | Mobile
Web01 | 2.8.140926.1 | Last Updated 9 Jun 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100