| | |
Convert String to Sql Datatype!!!
Please support our C# advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Sep 2008
Posts: 36
Reputation:
Solved Threads: 0
As the title says, how can i convert a string value to a Microsoft.SqlServer.Managment.Smo.Datatype ??? 
Example of code that im looking for:

Example of code that im looking for:
C# Syntax (Toggle Plain Text)
Using Microsoft.Sqlserver.Managment.Smo; public partial class 'FormName' { String datatype = "Nvarchar"; Microsoft.SqlServer.Managment.Smo.Datatype dt = datatype; }
Last edited by peter_budo; Sep 3rd, 2009 at 4:28 am. Reason: Adding missing [/code]
Yes but this is the wrong forum for C# questions, this is the SQL forum 
Please use the C# forum in the future but don't open a new thread for this question, it will be moved shortly!
To answer your question -- you don't want to do whatever you're attempting. The CLR and MSSQL driver handles the data conversion for. The SQL Data types are listed as an enumeration member. See
If this is not what you are wanting to do then please clarify what you are trying to accomplish.

Please use the C# forum in the future but don't open a new thread for this question, it will be moved shortly!
To answer your question -- you don't want to do whatever you're attempting. The CLR and MSSQL driver handles the data conversion for. The SQL Data types are listed as an enumeration member. See
System.Data.SqlDbType . C# Syntax (Toggle Plain Text)
using System; namespace System.Data { public enum SqlDbType { BigInt = 0, Binary = 1, Bit = 2, Char = 3, DateTime = 4, Decimal = 5, Float = 6, Image = 7, Int = 8, Money = 9, NChar = 10, NText = 11, NVarChar = 12, Real = 13, UniqueIdentifier = 14, SmallDateTime = 15, SmallInt = 16, SmallMoney = 17, Text = 18, Timestamp = 19, TinyInt = 20, VarBinary = 21, VarChar = 22, Variant = 23, Xml = 25, Udt = 29, Structured = 30, Date = 31, Time = 32, DateTime2 = 33, DateTimeOffset = 34, } }
If this is not what you are wanting to do then please clarify what you are trying to accomplish.
•
•
Join Date: Sep 2008
Posts: 36
Reputation:
Solved Threads: 0
•
•
•
•
Yes but this is the wrong forum for C# questions, this is the SQL forum
Please use the C# forum in the future but don't open a new thread for this question, it will be moved shortly!
To answer your question -- you don't want to do whatever you're attempting. The CLR and MSSQL driver handles the data conversion for. The SQL Data types are listed as an enumeration member. SeeSystem.Data.SqlDbType.
C# Syntax (Toggle Plain Text)
using System; namespace System.Data { public enum SqlDbType { BigInt = 0, Binary = 1, Bit = 2, Char = 3, DateTime = 4, Decimal = 5, Float = 6, Image = 7, Int = 8, Money = 9, NChar = 10, NText = 11, NVarChar = 12, Real = 13, UniqueIdentifier = 14, SmallDateTime = 15, SmallInt = 16, SmallMoney = 17, Text = 18, Timestamp = 19, TinyInt = 20, VarBinary = 21, VarChar = 22, Variant = 23, Xml = 25, Udt = 29, Structured = 30, Date = 31, Time = 32, DateTime2 = 33, DateTimeOffset = 34, } }
If this is not what you are wanting to do then please clarify what you are trying to accomplish.
OK -- just so you know the .NET Framework converts the data types for you. Here is an example SQL call that brings a
varchar() back from the SQL Server in the form of a C# string : C# Syntax (Toggle Plain Text)
private static DataTable LookupUser(string Username) { /* * The reason I return a datatable here is so you can also bring back the user's full * name, email address, security rights in the application, etc. I have a "User" class * where I defined meta information for users. */ const string connStr = "Data Source=apex2006sql;Initial Catalog=Leather;Integrated Security=True;"; const string query = "Select Password From UserTable (NOLOCK) Where UserName = @UserName"; DataTable result = new DataTable(); using (SqlConnection conn = new SqlConnection(connStr)) { conn.Open(); using (SqlCommand cmd = new SqlCommand(query, conn)) { cmd.Parameters.Add("@UserName", SqlDbType.VarChar).Value = Username; using (SqlDataReader dr = cmd.ExecuteReader()) { result.Load(dr); string textBoxStuff = Convert.ToString(result.Rows[0]["Column"]); } } } return result; }
![]() |
Similar Threads
- how to convert string values to date and compare them while using an array (JSP)
- Convert from String to Decimal and insert into SQL (C#)
- Convert string to to HEX (C)
- How to convert string to const char* in C (C++)
- Convert string "aA" to a BigInteger (Java)
Other Threads in the C# Forum
- Previous Thread: Can't open new WindowsForm
- Next Thread: c# and excel: chart ranges
| Thread Tools | Search this Thread |
.net access algorithm array barchart bitmap box broadcast c# check checkbox client combobox control conversion csharp custom cyclethruopenforms data database datagrid datagridview dataset date/time datetime degrees development dll draganddrop drawing encryption enum event excel file finalyearproject form format forms function gdi+ getoutlookcontactusinfcsvfile globalization httpwebrequest image index input install installer java label list listbox mandelbrot math mono mouseclick mysql operator panel path photoshop picturebox pixelinversion post programming radians regex remote remoting richtextbox save server silverlight sleep socket sql sql-server statistics stream string table text textbox thread time timer timespan update usercontrol users validate validation visualstudio webbrowser wia windows winforms wpf xml






