• 28-04-2020, 15:10:43
    #1
    a sını yaptım ama b ve c yi yapamadım nasıl kod ile yazdırabilirim bilgili abilerim yardımcı olursa çok sevinirim yaptıgım kodu buraya bırakıyorum
     public partial class Form1 : Form
    {
    public Form1()
    {
    InitializeComponent();
    }
    
    private void Form1_Load(object sender, EventArgs e)
    {
    SqlConnection con = new SqlConnection(@"server=DESKTOP-438B91R\SQL;Trusted_Connection=yes");
    string str = string.Format("create database db_test");
    SqlCommand myCommand = new SqlCommand(str, con);
    try
    {
    con.Open();
    myCommand.ExecuteNonQuery();
    MessageBox.Show("Başarılı", "prog", MessageBoxButtons.OK, MessageBoxIcon.Information);
    }
    catch (System.Exception ex)
    {
    MessageBox.Show(ex.ToString(), "prog", MessageBoxButtons.OK, MessageBoxIcon.Information);
    }
    finally
    {
    if (con.State == ConnectionState.Open)
    {
    con.Close();
    }
    }
    }
    
    }
    }
  • 28-04-2020, 18:02:41
    #2
    ayni komutlari kullanabilirsin.. Tek degisen sey str degiskeni olmali..
    Sanirim takildigin yer,coklu satir oldugu icin

    string str = string.Format("create table [student]( {0}",Envirionment.NewLine) +
    string.Format("[ID] [int] IDENTITY(1,1) PRIMARY KEY, {0}",Envirionment.NewLine) +
    ..... BURALARI ÜSTTEKI RESIMDEKI KODLARA GÖRE TAMAMLA
    ....
    string.Format("[MOB] [nvarchar](50) NULL)");

    yapman kafidir..
    daha sonra ayni diger yaptigin koddaki gibi cagirirsan olur..
    Envirionment.NewLine kodu yeni satir olusturur. Koymak zorunda degilsin elbette o zaman tek satir kod olur.. o da calisir ama bosluk koyduguna dikkat et yani söyle
    string str = "create table [student]( " +
    "[ID] [int] IDENTITY(1,1) PRIMARY KEY, " +
    "......eksik kodlari tamamla " +
    "......eksik kodlari tamamla " +
    "MOB] [nvarchar](50) NULL )");

    dikkat edersen en sondaki cift tirnaktan hemen önce bosluk var.. bu sekilde de yapabilirsin..
    kolay gelsin