473,387 Members | 1,638 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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

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
3 2854
Frinavale
9,735 Expert Mod 8TB
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
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
Thanks Coding master! I'm trying.
Nov 21 '12 #4

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

Similar topics

3
by: Parrot | last post by:
Does anyone else have a problem with the Mozilla browser not expanding a multi-line textbox to its proper size? My textboxes are all small and do not display mu;tiple lines in Mozilla or Netscape...
2
by: Mr.Baha | last post by:
Hello, I have a situation where I am appending text to a multi-line (rich)textbox in a C# form. Now depending on which event does the appendtext, i want to distinguish the lines in the textbox by...
1
by: VMI | last post by:
In my Windows app, if I'm in a multi-line textbox and I'm writing a postal address (ie. write ist line and press <Enter>, write 2nd line and press <Enter>, etc...) how can I make sure that the...
1
by: JL | last post by:
Hi, Can i check the user press the <enter> key in multi-line textbox? cos i don't want user use the <enter> key to change the line in textbox, just want the line warp change the line. Thanks...
2
by: John Carnahan | last post by:
I have a problem writing the text from a multi-line textbox to the Sql Server db. If the user sends a vbcrlf (enter key) in the middle of the entered text, the text gets truncated at the vbcrlf...
2
by: Tony Dong | last post by:
HI there I make a data binding for list box, and it is multi selects, everything working fine, but How can I get the multi select values in windows form? I try many ways for...
2
by: Agnes | last post by:
Does the textbox in vb.net (alllow input multi-line ??) In vfp, there is "editbox" , which allow user to input several lines data and save in the table 'as memo field' However, I can't find the...
4
by: zoneal | last post by:
I have a multi line textbox with word wrap enabled. Is it possible to write code to check if the text of the textbox has continued into the next line and then count the amount of lines? If not...
2
by: BillE | last post by:
I need to create a multi-line label dynamically. Since labels aren't multi-line, I'm creating a textbox and making it look like a label with the multiline property set to true. I want to...
8
by: cj | last post by:
I use multi-line text boxes with vertical scroll bars in several of my programs to display log information as the programs run. Once the text more than fills the visible portion of the textbox I...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.