Click here to Skip to main content
15,891,529 members
Please Sign up or sign in to vote.
3.67/5 (2 votes)
See more:
Hi,

I am using a data table and want to insert value from text box what is the source code for that.
After entering all records finally use submit button for save to database.

My data table code is:

protected void btnAdd_Click(object sender, EventArgs e)
       {
           //SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["connectionstring"].ToString());
           //SqlDataAdapter da = new SqlDataAdapter("select product_name,product_quantity,product_amount from product_order", con);

           DataTable dt = new DataTable();
           dt.Columns.Add("Product_Name");
           dt.Columns.Add("Product_Quantity");
           dt.Columns.Add("Product_Amount");

           DataRow dr = dt.NewRow();
           dt.Rows.Add(dr);
           dr[0] = DropDownList1.SelectedItem.Text;
           dr[1] = txtqty.Text;
           dr[2] = txtAmount.Text;


       }
Posted
Updated 16-Sep-10 0:03am
v2

Hi,

//Your DataTable
DataTable myDataTable = new DataTable();

DataColumn myDataColumn;

myDataColumn = new DataColumn();
myDataColumn.DataType = Type.GetType("System.String");
myDataColumn.ColumnName = "id";
myDataTable.Columns.Add(myDataColumn);

myDataColumn = new DataColumn();
myDataColumn.DataType = Type.GetType("System.String");
myDataColumn.ColumnName = "username";
myDataTable.Columns.Add(myDataColumn);

//Now to add the TextBox value in a row column

DataRow row;

row = myTable.NewRow();

row["id"] = Guid.NewGuid().ToString();
row["username"] = TextBox1.Text;// Here you are assigning the value

myTable.Rows.Add(row); //Add the row to a table

Thanks & Regards,
Jeevan.
 
Share this answer
 
Comments
call to .net 16-Sep-10 9:23am    
thanks for yr code but i am not able to access input data that i have giving input from text box and drop downlist on add button click event.
This is a very basic thing you are asking.
I suggest you to read some book or visit google.

I am downvoting this, cause its clear that you have not put in any efforts to search the solution or learn the thing.
 
Share this answer
 
v2

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