Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: SQL-Server VB.NET TextBoxBase , +
Hi everyone!,
 
I'm trying to create a project, so that I will have the opportunity to refill the table on SQL server. The table is created and it has several columns. I searched the internet, but did not come across to the the solution I'm looking for. Maybe, I will explain first what would my form do (how should it be)
 
The user entered the form is oblige to completed several fields. (1 control is Textbox (single value), all other controls are TextBox.Multiline.
Each of them would save the data to a SQL table. And here comes the question of how to do to it, after filling the first textbox (which is single.value) with data by the user (let's say this is one value that identifies the country in which he lives - Poland), he will put the data to the second textbox (multiple) called"Cities" (and gives for example 6 examples - Warsaw, Katowice, Wrocław, Krak?w, Gdańsk, Gdynia) had the option to save it in a SQL table like that:
 
Country    Cities
Poland     Warsaw
Poland     Katowice
Poland     Wroclaw
Poland     Krakow
Polish     Gdańsk
Poland     Gdynia
 
I hope there is a solution that will not only save the value - Poland to the first empty cell in the column to only the amount, to any user adds value textboxie 2 Of course, there are a few testbox?w like this on my form - just six, but the point is that I would like to have the option of sorting the data entered by the user X, got Y the country, showing only the data that are associated with these variables from textbox one (single).
 
I hope I explained it properly....
Best Regards
M
Posted 3-Jul-13 6:42am
Edited 3-Jul-13 9:20am
Maciej Los136.3K
v3
Comments
CHill60 at 3-Jul-13 14:31pm
   
Which bit are you stuck on? Writing the SQL or analysing the data that has been entered
LordVovin at 3-Jul-13 14:51pm
   
Well, I've made insert into statement with parameters for upload, and it works, but after upload to the database (to the table), I have my form, where I can choose the data from the comboboxes (I will choose Poland for example, then Warsaw, and in third combobox I can see all items for Warsaw), but when I want to change the item in City combobox, they're getn' multiplaying in it...
Maciej Los at 3-Jul-13 15:44pm
   
In my opinion, your UI design is bad. Use 2 textboxes and one listbox or listview or datagridview. In the first textbox user can type Country and in the second text box user can type city. After that He/She clicks on a Buton "Add" and listview/datagidview displays all entered data. Is it acceptable for you?
 
BTW, i live in Poland, Bialystok city ;)
LordVovin at 3-Jul-13 16:06pm
   
the thing is that, they're updating it using excel file, which we get from the market (vendor). We have Country, City, Invoice type, activity type, additional type. And there are few records with the data. So I would liek to add data from "excel columns" (for example City) to multiple textbox City, and other data from other columns using metod - Copy Paste ;) After the employee will put all the data into the form, I can see it, and then, I can mamange their work. After my "check" in the form with comboboxes that I mentioned earlier, They will use their version with values that I will assign for them (using user name)...so it's a little bit more complicated ;)
 
hehe, I'm from Wroclaw :)
Nice to meet you :) - virtually, but always :)
Thank you!

1 solution

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

Solution 1

Not sure I am following exactly, but is sounds like you are just trying to get the lines of a multi-line textbox and store them.
 
For Each Str As String In Me.TextBox2.Lines
            MsgBox(Str)
 Next
 
If you have country in say textbox1 then you can use
 
For Each Str As String In Me.TextBox2.Lines
           MsgBox(TextBox1.Text & Str)
Next
 
Replacing msgbox of course with your record source.
  Permalink  
Comments
LordVovin at 4-Jul-13 3:24am
   
Hi John,
 
thanks for your solution. I've done it already :)
 
My code is like this:
 
Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
Dim con As SqlConnection = New SqlConnection("Data Source=SZYNDLEM2\DHLSERVER;Initial Catalog=TimerTool;Integrated Security=True")
'Dim affectedRows As Integer
If CheckBox1.Checked = True Then
txtInvTcheck.Text = "true"
Else
txtInvTcheck.Text = "false"
End If
If CheckBox2.Checked = True Then
txtAddCheck.Text = "true"
Else
txtAddCheck.Text = "false"
End If
Dim acc As String = Me.txtCountry.Text
Dim tow As String = Me.txtTower.Text
Dim pro As String = Me.txtProcess.Text
Dim ich As String = Me.txtInvTcheck.Text
Dim ach As String = Me.txtAddCheck.Text
Dim usr As String() = Me.txtUserAdd.Text.Split(New [Char]() {","c, "."c, ":"c, CChar(vbTab), CChar(vbCrLf)})
Dim typ As String() = Me.txtCity.Text.Split(New [Char]() {","c, "."c, ":"c, CChar(vbTab), CChar(vbCrLf)})
Dim inv As String() = Me.txtInvoiceAdd.Text.Split(New [Char]() {","c, "."c, ":"c, CChar(vbTab), CChar(vbCrLf)})
Dim add As String() = Me.txtAddActiv.Text.Split(New [Char]() {","c, "."c, ":"c, CChar(vbTab), CChar(vbCrLf)})
If con.State <> ConnectionState.Open Then
con.Open()
'MsgBox("Open")
Else
'MsgBox("Error!!")
End If
For Each user As String In usr
If user.Trim() <> "" Then
For Each Type As String In typ
If Type.Trim() <> "" Then
For Each invo As String In inv
If invo.Trim() <> "" Then
For Each addi As String In add
If addi.Trim() <> "" Then
 
Dim constr As String = "INSERT INTO tblAdministratorData (TimerAccount, TimerTower, TimerProcess, UserT, CityT, InvoiceType, [Additional], InvoiceCheckT, AdditionalCheckT) VALUES (@Account, @Tower, @Process, @User, @CityT, @Invoice, @Additional, @InvCheck, @AddCheck)"
Dim cmd As SqlCommand = New SqlCommand(constr, con)
cmd.Parameters.AddWithValue("@CityT", DbNullOrStringValue(type))
cmd.Parameters.AddWithValue("@Invoice", DbNullOrStringValue(invo))
cmd.Parameters.AddWithValue("@Additional", DbNullOrStringValue(addi))
cmd.Parameters.AddWithValue("@User", DbNullOrStringValue(user))
cmd.Parameters.AddWithValue("@process", DbNullOrStringValue(pro))
cmd.Parameters.AddWithValue("@Tower", DbNullOrStringValue(tow))
cmd.Parameters.AddWithValue("@Account", DbNullOrStringValue(acc))
cmd.Parameters.AddWithValue("@InvCheck", DbNullOrStringValue(ich))
cmd.Parameters.AddWithValue("@AddCheck", DbNullOrStringValue(ach))
cmd.ExecuteNonQuery()
 

End If
Next addi
End If
Next invo
End If
Next Type
End If
Next user
con.Close()
MsgBox("Closed, Saved!")
End Sub
 

Now I'm fighting with DBnull.Value...;/....
 
for DbNullOrStringValue I have this code:
 
Public Function DbNullOrStringValue(ByVal value As String) As Object
If String.Is
LordVovin at 4-Jul-13 3:25am
   
for DbNullOrStringValue i have this code:
 
Public Function DbNullOrStringValue(ByVal value As String) As Object
If String.IsNullOrEmpty(value) Then
Return DBNull.Value
Else
Return value
End If
End Function
 

but unfortunately - no effect
Thanks!

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

  Print Answers RSS
0 mhegazy94 460
1 Sergey Alexandrovich Kryukov 405
2 Kornfeld Eliyahu Peter 285
3 Gihan Liyanage 167
4 Sibeesh KV 150
0 Sergey Alexandrovich Kryukov 6,805
1 OriginalGriff 6,696
2 CPallini 5,350
3 George Jonsson 3,609
4 Gihan Liyanage 2,792


Advertise | Privacy | Mobile
Web02 | 2.8.140922.1 | Last Updated 3 Jul 2013
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