using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Data.SqlClient; using System.Data.Common; namespace Netz_Vorgang { public partial class Form1 : Form { SqlConnection connection = new SqlConnection("Data Source=STEPHANE-YOTAT\\STEPHANE;Initial Catalog=DBtest;Trusted_Connection=Yes"); public Form1() { InitializeComponent(); try { connection.Open(); } catch (Exception ex) { MessageBox.Show("error occured 2 " + ex.Message); this.Dispose(); } } private void Form1_Load(object sender, EventArgs e) { } private void _insert_Click(object sender, EventArgs e) { string com = string.Format("insert into Step values('{0}', '{1}')", (string)(_StepName.Text.ToString()), Int32.Parse(_Dauer.Text)); SqlCommand com2 = new SqlCommand(com,connection); try { com2.ExecuteNonQuery(); connection.Dispose(); MessageBox.Show("successfull"); _StepName.Text.Equals( ""); _Dauer.Text = ""; _StepName.Focus(); this.Update(); } catch (Exception ex) { MessageBox.Show("error occured 1" + ex.Message); this.Dispose(); } } private void _show_Click(object sender, EventArgs e) { SqlCommand connec = new SqlCommand("select * from Table",connection); DataSet vds = new DataSet(); SqlDataAdapter vda = new SqlDataAdapter(connec); vda.Fill(vds,"ret"); dataGridView1.DataSource = vds.Tables["ret"]; connection.Dispose(); } } }
_show_Click
onnection.Dispose();
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)