Click here to Skip to main content
15,897,360 members
Home / Discussions / C#
   

C#

 
AnswerRe: decimal question Pin
Luc Pattyn20-May-10 2:51
sitebuilderLuc Pattyn20-May-10 2:51 
QuestionPrint certificate Pin
Jassim Rahma19-May-10 23:07
Jassim Rahma19-May-10 23:07 
AnswerRe: Print certificate Pin
OriginalGriff20-May-10 0:15
mveOriginalGriff20-May-10 0:15 
QuestionChange SQL Server dateformat? Pin
Dotnetkanna19-May-10 22:44
Dotnetkanna19-May-10 22:44 
AnswerRe: Change SQL Server dateformat? Pin
Hristo-Bojilov19-May-10 22:55
Hristo-Bojilov19-May-10 22:55 
AnswerRe: Change SQL Server dateformat? Pin
T M Gray20-May-10 11:44
T M Gray20-May-10 11:44 
QuestionCreating Tables in Run time using c# Pin
Raghu_M19-May-10 22:33
Raghu_M19-May-10 22:33 
AnswerRe: Creating Tables in Run time using c# Pin
Pete O'Hanlon19-May-10 23:25
mvePete O'Hanlon19-May-10 23:25 
You could always just write the SQL to create a table and execute it using a SqlCommand, but a better way to do it would be to use Sql Server Management Objects (SMO).
private void MakeMyTable()
{
  string connectionString = "...";
  using (SqlConnection connection = new SqlConnection(connectionString))
  {
    Server server =
      new Server(new ServerConnection(connection));

    // Create table in my personal database
    Database db = server.Databases["MyDatabase"];

    // Create new table, called TestTable
    Table newTable = new Table(db, "MyTestTable");

    // Create the primary key
    Column pk = GetColumn(newTable, "id", DataType.Int, false);
    pk.Identity = true;
    pk.IdentitySeed = 1;
    pk.IdentityIncrement = 1;

    newTable.Add(pk);

    DataType varchar = new DataType(SqlDataType.NVarChar, 50);
    newTable.Add(GetColumn(newTable, "Name", varchar, false));
    newTable.Add(GetColumn(newTable, "Nickname", varchar, true));
    newTable.Add(GetColumn(newTable, "Title", varchar, false));

    // Create a PK Index for the table
    Index index = new Index(newTable, "PK_MyTestTable");
    index.IndexKeyType = IndexKeyType.DriPrimaryKey;

    // The PK index will consist of 1 column, "ID"
    index.IndexedColumns.Add(new IndexedColumn(index,"id"));

    // Add the new index to the table.
    newTable.Indexes.Add(index);

    // Physically create the table in the database
    newTable.Create();
  }
}

private Column GetGolumn(Table tb, string columnName, DataType type, bool isNullable)
{
  Column column = new Column(tb, columnName);
  column.DataType = type;
  column.Nullable = nullable;
}

"WPF has many lovers. It's a veritable porn star!" - Josh Smith

As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.


My blog | My articles | MoXAML PowerToys | Onyx



Questionhow to check operating system in c#..? Pin
NetMan201219-May-10 22:07
NetMan201219-May-10 22:07 
AnswerRe: how to check operating system in c#..? Pin
The Man from U.N.C.L.E.19-May-10 22:18
The Man from U.N.C.L.E.19-May-10 22:18 
AnswerRe: how to check operating system in c#..? Pin
Pete O'Hanlon19-May-10 22:30
mvePete O'Hanlon19-May-10 22:30 
AnswerRe: how to check operating system in c#..? Pin
Johnny J.19-May-10 22:33
professionalJohnny J.19-May-10 22:33 
AnswerRe: how to check operating system in c#..? Pin
Dave Kreskowiak20-May-10 1:29
mveDave Kreskowiak20-May-10 1:29 
AnswerRe: how to check operating system in c#..? Pin
Luc Pattyn20-May-10 3:00
sitebuilderLuc Pattyn20-May-10 3:00 
GeneralRe: how to check operating system in c#..? Pin
Pete O'Hanlon20-May-10 3:36
mvePete O'Hanlon20-May-10 3:36 
GeneralRe: how to check operating system in c#..? Pin
Luc Pattyn20-May-10 3:55
sitebuilderLuc Pattyn20-May-10 3:55 
GeneralRe: how to check operating system in c#..? Pin
Pete O'Hanlon20-May-10 3:59
mvePete O'Hanlon20-May-10 3:59 
GeneralRe: how to check operating system in c#..? Pin
Dave Kreskowiak20-May-10 6:35
mveDave Kreskowiak20-May-10 6:35 
GeneralRe: how to check operating system in c#..? Pin
Johnny J.20-May-10 21:01
professionalJohnny J.20-May-10 21:01 
GeneralRe: how to check operating system in c#..? Pin
Dave Kreskowiak21-May-10 1:45
mveDave Kreskowiak21-May-10 1:45 
AnswerRe: how to check operating system in c#..? Pin
canangirgin20-May-10 4:41
canangirgin20-May-10 4:41 
QuestionDisposing of object used in a UserControl... Pin
Shy Agam19-May-10 21:40
Shy Agam19-May-10 21:40 
AnswerRe: Disposing of object used in a UserControl... Pin
Pete O'Hanlon19-May-10 22:11
mvePete O'Hanlon19-May-10 22:11 
GeneralRe: Disposing of object used in a UserControl... Pin
Luc Pattyn20-May-10 3:20
sitebuilderLuc Pattyn20-May-10 3:20 
GeneralRe: Disposing of object used in a UserControl... Pin
Pete O'Hanlon20-May-10 3:50
mvePete O'Hanlon20-May-10 3:50 

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.