Click here to Skip to main content
15,917,454 members
Home / Discussions / Database
   

Database

 
AnswerRe: Getting the connection string Pin
Rob Graham29-Mar-07 9:10
Rob Graham29-Mar-07 9:10 
QuestionHow can I Inserting to a table Pin
mghiassi29-Mar-07 6:46
mghiassi29-Mar-07 6:46 
AnswerRe: How can I Inserting to a table Pin
Colin Angus Mackay29-Mar-07 21:16
Colin Angus Mackay29-Mar-07 21:16 
Questionprivate Table Adapters Pin
Drathmar29-Mar-07 5:49
Drathmar29-Mar-07 5:49 
QuestionServer Error in '/aspx' Application. Pin
nothingbutcat29-Mar-07 5:07
nothingbutcat29-Mar-07 5:07 
AnswerRe: Server Error in '/aspx' Application. Pin
Colin Angus Mackay29-Mar-07 5:22
Colin Angus Mackay29-Mar-07 5:22 
GeneralRe: Server Error in '/aspx' Application. Pin
nothingbutcat29-Mar-07 6:44
nothingbutcat29-Mar-07 6:44 
QuestionConvert .NET Framework types to SQL data type? Pin
Gywox29-Mar-07 4:24
Gywox29-Mar-07 4:24 
Hi Everyone!
Is there any way by which I can convert .NET Framework types to SQL data type to be used by a Create Table command?
Some code to explain what I intend to do:

<code>public class SqlTableAdapter<T> where T : new()

...

// Get properties of a generic class what I want to create a sql table from.

PropertyInfo[] properties = typeof(T).GetProperties(BindingFlags.Public | BindingFlags.Instance);
for (int indexProperty = 0; indexProperty < properties.Length; indexProperty++)
{
    Object[] attributes = properties[indexProperty].GetCustomAttributes(typeof(DataObjectFieldAttribute), true);
    if (attributes.Length > 0)
    {
        DataObjectFieldAttribute dataObjectField = attributes[0] as DataObjectFieldAttribute;
        DataColumn dataColumn = new DataColumn(properties[indexProperty].Name, properties[indexProperty].PropertyType);
        dataColumn.Unique = dataObjectField.IsIdentity;
        dataColumn.AllowDBNull = dataObjectField.IsNullable;
        if (properties[indexProperty].PropertyType == typeof(string))
        {
              dataColumn.MaxLength = dataObjectField.Length;
        }

        // The problem is here to convert the system type ! I don't have a method SqlTypeConvert.
        dataColumn.SqlType = SqlTypeConvert( properties[indexProperty].PropertyType );

        dataColumns.Add(dataColumn);
    }
}

...

// Create a Sql column definition, ex. columnDefinition="CustID int PRIMARY KEY, CompanyName nvarchar (50)" from the dataColumns list.

...

DbCommand commandCreateTable = this.Connection.CreateCommand();
commandCreateTable.Connection = this.Connection;
commandCreateTable.CommandText = string.Format("CREATE TABLE [{0}] ({1})", typeof(T).ToString(), columnDefinition);
commandCreateTable.CommandType = CommandType.Text;


Thanks in advanced for your help
Gywox


-- modified at 10:29 Thursday 29th March, 2007
Questionconvert datetime Pin
Test27030729-Mar-07 0:16
Test27030729-Mar-07 0:16 
AnswerRe: convert datetime Pin
Colin Angus Mackay29-Mar-07 0:47
Colin Angus Mackay29-Mar-07 0:47 
GeneralRe: convert datetime Pin
Test27030729-Mar-07 1:00
Test27030729-Mar-07 1:00 
GeneralRe: convert datetime Pin
Colin Angus Mackay29-Mar-07 3:16
Colin Angus Mackay29-Mar-07 3:16 
AnswerRe: convert datetime Pin
Krish - KP29-Mar-07 1:39
Krish - KP29-Mar-07 1:39 
GeneralRe: convert datetime Pin
Test27030729-Mar-07 1:52
Test27030729-Mar-07 1:52 
AnswerRe: convert datetime Pin
Chetan Patel29-Mar-07 21:00
Chetan Patel29-Mar-07 21:00 
QuestionSnap-in failed to initilize error on enterprise manager Pin
mohd imran abdul aziz28-Mar-07 21:02
mohd imran abdul aziz28-Mar-07 21:02 
QuestionDuplicate records Pin
Sophia Rekhi28-Mar-07 18:55
Sophia Rekhi28-Mar-07 18:55 
AnswerRe: Duplicate records Pin
jijoaresseriljose28-Mar-07 21:33
jijoaresseriljose28-Mar-07 21:33 
GeneralRe: Duplicate records Pin
Sophia Rekhi28-Mar-07 23:10
Sophia Rekhi28-Mar-07 23:10 
AnswerRe: Duplicate records Pin
Krish - KP29-Mar-07 1:46
Krish - KP29-Mar-07 1:46 
GeneralRe: Duplicate records [modified] Pin
jijoaresseriljose29-Mar-07 3:31
jijoaresseriljose29-Mar-07 3:31 
AnswerRe: Duplicate records Pin
Krish - KP28-Mar-07 21:37
Krish - KP28-Mar-07 21:37 
AnswerRe: Duplicate records Pin
one_stone_zz28-Mar-07 23:21
one_stone_zz28-Mar-07 23:21 
Questionhow do i Decryption Store Procedure ...? Pin
PavanPareta28-Mar-07 3:50
PavanPareta28-Mar-07 3:50 
AnswerRe: how do i Decryption Store Procedure ...? Pin
Pete O'Hanlon28-Mar-07 4:36
mvePete O'Hanlon28-Mar-07 4:36 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.