RichTextBox - the correct choice and how to loop

  • Thread starter Thread starter JCCDevel
  • Start date Start date
J

JCCDevel

Hello,

I'm working on a pretty simple web app in which the user will be
pasting in a list of values (letters and number - like "1V456") most
likely from an Excel worksheet. I then want the application to check
this list against tables in a sql server database for different things
(like - does it exist in database, etc.) My co-worker thinks that a
richtextbox is the best control to use for this. I'm new to VB.Net so
I'm not real familiar with this control. Is it the right way to go?
I've been doing a little research on the web and don't see it used too
much for this situation. I have been playing with it a bit and have
gotten results to point to a table, but it is adding in strange
characters and blank entires. Here is the code:

<code>


For Each str As String In RichTextBox1.Lines
InsertSQL = "Insert into Test_test values ('" & str & "
')"
dr1 = SqlHelper.ExecuteReader(CONNSTRING,
CommandType.Text, InsertSQL)
Next

</code>

Is a "For each" statement the way to go?

Thanks in advance for your time!

JCC
 
JCCDevel said:
Hello,

I'm working on a pretty simple web app in which the user will be
pasting in a list of values (letters and number - like "1V456") most
likely from an Excel worksheet. I then want the application to check
this list against tables in a sql server database for different things
(like - does it exist in database, etc.) My co-worker thinks that a
richtextbox is the best control to use for this. I'm new to VB.Net so
I'm not real familiar with this control. Is it the right way to go?
I've been doing a little research on the web and don't see it used too
much for this situation. I have been playing with it a bit and have
gotten results to point to a table, but it is adding in strange
characters and blank entires. Here is the code:

<code>


For Each str As String In RichTextBox1.Lines
InsertSQL = "Insert into Test_test values ('" & str & "
')"
dr1 = SqlHelper.ExecuteReader(CONNSTRING,
CommandType.Text, InsertSQL)
Next

</code>

Is a "For each" statement the way to go?

Thanks in advance for your time!


I don't see any problems in what you're doing. Does it work for you? That's
all that counts is that it works for you. There several ways that one could
possibly do things, but just use the one you are using.

I would stick with what you got.

However, you need to do a SqlBless function on the str SqlBless(str) on that
Insert statement, because special characters can be in that str that can
make the Insert terminate, if they are not accounted for on the Insert.

You can use Google to lookup SqlBless and apply the function in your
program.
 
Mr. Arnold said:
I don't see any problems in what you're doing. Does it work for you?
That's all that counts is that it works for you. There several ways that
one could possibly do things, but just use the one you are using.

I would stick with what you got.

However, you need to do a SqlBless function on the str SqlBless(str) on
that Insert statement, because special characters can be in that str that
can make the Insert terminate, if they are not accounted for on the
Insert.

You can use Google to lookup SqlBless and apply the function in your
program.

You should be using parameters to execute your SQL statement.

InsertSQL = "Insert into Test_test values (@InsertValue)"

Then you are executing using a datareader. Since you are not reading
anything use ExecuteNonQuery

LS
 
Back
Top