How to use the varchar data type in c#?

后端 未结 3 568
时光取名叫无心
时光取名叫无心 2021-01-22 23:24

I have this piece of code and I want to make it varchar not string. What is the appropriate syntax to do that in c#

 string emri = row[\"Nome\"].ToString();
         


        
3条回答
  •  再見小時候
    2021-01-22 23:46

    NO this is untrue, When you step through a process by changing the debugging settings located in VS you can step through a SQL script process also if you run an example like this where a table has varchar values set into it.

    Try
    {
      using (SqlCommand cmd = new SqlCommand(examplestring, connection))
      {
        cmd.ExecutenonQuery();
      }
     }
     catch
     {
        return;
      }
    

    now put a breakpoint onto the catch statement and in the examplestring have a string called '456789 - 1' equal to Itemnumber varchar(25) in the SQL table.

    The catch will get the following error SqlException was caught - Error converting data type varchar to numeric.

    Now query string is set as a string cause that is the only way the SqlCommand works look it up on MSDN : System.Data.SqlClient.SqlCommand

    So yes Lasse there is varchar in .NET.

提交回复
热议问题