By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,899 Members | 1,230 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,899 IT Pros & Developers. It's quick & easy.

How to save multi line values in textbox into multi rows in sql

P: 2
I'm trying to save multi line values in textbox into multi rows in sql. I have a textbox as shown in below image

http://www.4shared.com/photo/91DD7knd/Multi-textbox.html

After save, I want in data sql as below:

http://www.4shared.com/photo/8yEVRPbV/Data-Sql.html

Please help me to achieve this in possible, thank you!
Nov 19 '12 #1
Share this Question
Share on Google+
3 Replies


Frinavale
Expert Mod 5K+
P: 9,731
I the method that you have implemented that does the saving, retrieve the string from the multi-line TextBox and split it on New Lines.

Once you have it split, loop through the elements and create a new string based on 3 elements in the split.

Then create your insert statements and insert your rows according to your business rules.

-Frinny
Nov 19 '12 #2

P: 11
huynhtienlinh----- you can try this code

this code mainly build for excel sheet......

Expand|Select|Wrap|Line Numbers
  1.  string connectionString = "";
  2.         if (DATAbring.HasFile)
  3.         {
  4.             string fileName = System.IO.Path.GetFileName(DATAbring.PostedFile.FileName);
  5.             string fileExtension = System.IO.Path.GetExtension(DATAbring.PostedFile.FileName);
  6.             string fileLocation = Server.MapPath("~/App_Data/" + fileName);
  7.             DATAbring.SaveAs(fileLocation);
  8.  
  9.  
  10.             if (fileExtension == ".xls")
  11.             {
  12.                 connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + fileLocation + ";Extended Properties=\"Excel 8.0;HDR=Yes;IMEX=2\"";
  13.             }
  14.             else if (fileExtension == ".xlsx")
  15.             {
  16.                 connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + fileLocation + ";Extended Properties=\"Excel 12.0;HDR=Yes;IMEX=2\"";
  17.             }
  18.  
  19.             OleDbConnection con = new OleDbConnection(connectionString);
  20.             OleDbCommand cmd = new OleDbCommand();
  21.             cmd.CommandType = System.Data.CommandType.Text;
  22.             cmd.Connection = con;
  23.             OleDbDataAdapter dAdapter = new OleDbDataAdapter(cmd);
  24.             DataTable dtExcelRecords = new DataTable();
  25.             con.Open();
  26.             DataTable dtExcelSheetName = con.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
  27.             string getExcelSheetName = dtExcelSheetName.Rows[0]["Table_Name"].ToString();
  28.             cmd.CommandText = "SELECT * FROM [" + getExcelSheetName + "]";
  29.             dAdapter.SelectCommand = cmd;
  30.             dAdapter.Fill(dtExcelRecords);
  31.  
  32.             int p = dtExcelRecords.Rows.Count;
  33.             for (int i = 1; i <= p; i++)
  34.             {
  35.                 string name = Convert.ToString(dtExcelRecords.Rows[i - 1][0]);
  36.                 string mobile = Convert.ToString(dtExcelRecords.Rows[i - 1][1]);
  37.                 con1.Open();
  38.  
  39.                 if (mobile == "")
  40.                 {
  41.  
  42.                 }
  43.  
  44.                 else
  45.                 {
  46.                     SqlCommand cmmd = new SqlCommand("select C_Name from table_name where Mobile_no='" + mobile.ToString() + "'", con1);
  47.                     int dd = cmmd.ExecuteNonQuery();
  48.                     if (dd > 0)
  49.                     {
  50.  
  51.                     }
  52.                     else
  53.                     {
  54.                         dal d = new dal();
  55.                         SqlCommand cmd1 = new SqlCommand();
  56.                         cmd1 = new SqlCommand("insert into table_name(C_Name,Mobile_no)values('" + name + "','" + mobile + "')", con1);
  57.                         cmd1.ExecuteNonQuery();
  58.                     }
  59.                 }
  60.  
  61.                 con1.Close();
  62.             }
  63.  
  64.  
  65.  
Nov 21 '12 #3

P: 2
Thanks Coding master! I'm trying.
Nov 21 '12 #4

Post your reply

Sign in to post your reply or Sign up for a free account.