0

I need to convert some code which passes the parameters value to SqlCommand. I can't explain this in words. so, let me take an example.

Eg:

Currently i am doing this,

Dim value1 As String = "Reference Value 1"
sql_command = New SqlCommand(query, Cn)
sql_command.Parameters.AddWithValue("@Reference1", value1)

and i want to convert the last line and the resultant code will be as below

Dim value1 As String = "Reference Value 1"
sql_command = New SqlCommand(query, Cn)
command.Parameters.Add("@Reference1", SqlDbType.VarChar);
command.Parameters["@Reference1"].Value = value1 ;

I need to change similar kind of stuff in more than 400 files so is there any other way or shortcut or something like this so that i can save my time.

Also one more thing, if we implement like this then it will increase the performance?

4
  • I think there is none. How will you know the equivalent sql data type from your c# data type? I guess you need to manually update it. ..just an idea though.. Commented Aug 8, 2014 at 4:29
  • I know i need to do this manually but i just need to know is there any shortcut or something like this. and one more thing. every field is varchar in database. Commented Aug 8, 2014 at 4:34
  • Why do you think this would increase performance. And only shortcut I would be able to think of is ctrl+h to replace, but thisis only going to work if all code looks the same Commented Aug 8, 2014 at 4:34
  • by default it search for the NVarchar and if you convert that then it will search into the specific type only. and for another, there are different argument so i need to do this manually. thanks to Mark. Commented Aug 8, 2014 at 5:44

1 Answer 1

1

SqlCommand.Parameters.Add returns the parameter, so you can combine the two lines:

command.Parameters.Add("@Reference1", SqlDbType.VarChar).Value = value1;
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.