سلام دوستان
قصد دارم برنامه ای در سی شارپ بنویسم که توسط اون بانک اطلاعاتی، جدول را ایجاد ، تغییر یا حذف کنم.
در بخش اول برنامه یعنی ایجاد بانک اطلاعاتی به مشکل برخوردم و بانک اطلاعاتی ایجاد نمیشه میخواستم بدونم مشکل از کجاست ممنون از لطف شما
کد برنامه:
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.Data.SqlClient; namespace ADO { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private String conStr = null; private SqlConnection Con = null; private SqlCommand Cmd = null; String SQL = null; private void Form1_Load(object sender, EventArgs e) { button1.Text = "ایجاد بانک اطلاعاتی"; button2.Text = "ایجاد جدول"; button3.Text = "حذف جدول"; button4.Text = "تغییر ساختار جدول"; button5.Text = "خاتمه برنامه"; comboBox1.Items.Clear(); comboBox1.Items.Add("Bank"); comboBox1.Items.Add("Chek"); comboBox1.Items.Add("tblUser"); comboBox1.Items.Add("Shobe"); comboBox1.Items.Add("City"); comboBox1.Items.Add("Ostan"); comboBox1.Text = "انتخاب کنید"; this.RightToLeft = RightToLeft.Yes; this.Text = "ایجاد بانک اطلاعات و جداول آن"; } private void button1_Click(object sender, EventArgs e) { try { Con = new SqlConnection(conStr); if (Con.State == ConnectionState.Open) Con.Close(); conStr = "Integrated Security=SSPI; Initial Catalog=master; Data Source=DESKTOP-L4IVEI3;"; Con.ConnectionString = conStr; Con.Open(); SQL = "create database Chek on Primary (Name=Chek_data,filename="+ "'D:\\Abbas\\Chek_data.Mdf'" + ",Size=30) Log on (Name=Chek_Log,filename=" + "'D:\\Abbas\\Chek_log.Ldf'" + "Size =30) "; Cmd = new SqlCommand(SQL, Con); Cmd.CommandType = CommandType.Text; Cmd.ExecuteNonQuery(); Con.Close(); MessageBox.Show("بانک مورد نظر ایجاد شد"); } catch (Exception) { MessageBox.Show("خطا در ایجاد بانک"); } } private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { } private void button3_Click(object sender, EventArgs e) { { try { Con = new SqlConnection(conStr); if (Con.State == ConnectionState.Open) Con.Close(); conStr = "Integrated Security=SSPI; Initial Catalog=chek; Data Source=DESKTOP-L4IVEI3;"; Con.ConnectionString = conStr; Con.Open(); SQL = "drop table " + comboBox1.Text; Cmd = new SqlCommand(SQL, Con); Cmd.CommandType = CommandType.Text; Cmd.ExecuteNonQuery(); Con.Close(); MessageBox.Show("حذف شد "+comboBox1.Text +" جدول"); } catch (Exception) { MessageBox.Show("خطا رخ داد" + comboBox1.Text + "در حذف جدول"); } } } private void button2_Click(object sender, EventArgs e) { try { Con = new SqlConnection(conStr); if (Con.State == ConnectionState.Open) Con.Close(); conStr = "Integrated Security=SSPI;Initial Catalog=Chek;Data Source=DESKTOP-L4IVEI3;"; Con.ConnectionString = conStr; Con.Open(); if (comboBox1.Text == "Bank") SQL = "create table Bank(" + "BankCode Varchar (6) Primary Key," + "BankName Varchar (15) Not Null," + "ShobeCode Varchar (6) ," + "CityCode Varchar (6) ," + "Tel Varchar (15) ," + "CAddress Varchar (255) )"; else if (comboBox1.Text == "Chek") SQL = "create table Chek(" + "ChekNo Varchar (15) Primary Key," + "BankCode Varchar (6) Not Null," + "UserName Varchar (10) ," + "ChekType Varchar (1) ," + "SodorDta Varchar (10) ," + "RasidData Varchar (10) ," + "VosolData Varchar (10) ," + "Mablag numeric," + "Comment Varchar (255) )"; else if (comboBox1.Text == "tblUser") SQL = "create table tblUser(" + "UserName Varchar (10) Primary Key," + "Pass Varchar (10) ," + "FUser Varchar (50) ," + "LUser Varchar (50) ," + "Access Varchar (1) ," + "Photo VarBinary (Max) )"; else if (comboBox1.Text == "City") SQL = "create table City(" + "CityCode Varchar (6) Primary Key," + "CityName Varchar (30) ," + "OstanCode Varchar (6) )"; else if (comboBox1.Text == "Ostan") SQL = "create table Ostan(" + "OstanCode Varchar (6) Primary Key," + "OstanName Varchar (30) )"; else SQL = "create table Shobe(" + "ShobeCode Varchar (6) Primary Key," + "ShobeName Varchar (30) )"; Cmd = new SqlCommand(SQL, Con); Cmd.CommandType = CommandType.Text; Cmd.ExecuteNonQuery(); Con.Close(); MessageBox.Show("ایجاد شد"+comboBox1.Text+"جدول"); } catch (Exception) { MessageBox.Show("خطا رخ داد" + comboBox1.Text + "در ایجاد جدول"); } } private void button4_Click(object sender, EventArgs e) { try { Con = new SqlConnection(conStr); if (Con.State == ConnectionState.Open) Con.Close(); conStr = "Integrated Security=SSPI;Initial Catalog=Chek;Data Source=DESKTOP-L4IVEI3;"; Con.ConnectionString = conStr; Con.Open(); if (comboBox1.Text == "Bank") SQL = "alter table Bank ADD Discription varchar (250) NULL"; else if (comboBox1.Text == "Chek") SQL = "alter table Chek alter column Comment varchar (250)"; else if (comboBox1.Text == "Shobe") SQL = "alter table Shobe ADD Comment varchar (250)"; else if (comboBox1.Text == "City") SQL = "alter table City ADD Comment varchar (250)"; else if (comboBox1.Text == "Ostan") SQL = "alter table Ostan ADD Comment varchar (250)"; else SQL = "alter table tblUser alter column FUser varchar (20)"; Cmd = new SqlCommand(SQL, Con); Cmd.CommandType = CommandType.Text; Cmd.ExecuteNonQuery(); Con.Close(); MessageBox.Show("تغییر یافت" + comboBox1.Text + "جدول"); } catch (Exception) { MessageBox.Show("خطا رخ داد" + comboBox1.Text + "در تغییر جدول"); } } private void button5_Click(object sender, EventArgs e) { Close(); } } }
این پست در تاریخ {{ dateString(new Date(post.deleteDate)) }} توسط {{ post.deletedByUser }} حذف شده است.
دلیل حذف: {{ post.deleteReason ?? 'نامشخص' }}
زمان پاسخ گویی روز های شنبه الی چهارشنبه ساعت 9 الی 18
فقط به موضوعات مربوط به محصولات آموزشی و فروش پاسخ داده می شود