Skip to content

Instantly share code, notes, and snippets.

View tedliou's full-sized avatar

Ted Liou tedliou

View GitHub Profile
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;
@tedliou
tedliou / 【Visual C#】使用 Random 方法產生不重複亂數
Last active July 14, 2024 10:50
使用Random方法,產生多組亂數值並不重複,存到陣列中,並在控制項中顯示出來。
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;
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;
<title><!--{if !empty($navtitle)}-->$navtitle - <!--{/if}--><!--{if empty($nobbname)}--> $_G['setting']['bbname'] - <!--{/if}--> Powered by Discuz!</title>
<title><!--{if !empty($navtitle)}-->$navtitle<!--{/if}--><!--{if empty($nobbname)}--> $_G['setting']['bbname']<!--{/if}--></title>
string cmdsql = "INSERT INTO [dbo].[ttt] ([yn], [gn], [an], [sc], [am]) VALUES (11, 12, 13, 14, 15)";
SqlConnection sql = new SqlConnection(@"Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\bin\Debug\liusql.mdf;Integrated Security=True;Connect Timeout=30");
SqlCommand cmd = new SqlCommand(cmdsql, sql);
sql.Open();
cmd.ExecuteNonQuery();
sql.Close();
//資料庫
string cmdsql = "SQL指令";
SqlConnection sql = new SqlConnection(@"Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\資料庫名稱.mdf;Integrated Security=True;Connect Timeout=30");
SqlCommand cmd = new SqlCommand(cmdsql, sql);
sql.Open();
cmd.ExecuteNonQuery();
sql.Close();
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;
string cmdsql = "INSERT INTO [Table] (test) VALUES ('"+textBox1.Text+"')";
SqlConnection sql = new SqlConnection(@"Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\Database1.mdf;Integrated Security=True;Connect Timeout=30");
SqlCommand cmd = new SqlCommand(cmdsql, sql);
sql.Open();
cmd.ExecuteNonQuery();
sql.Close();
SqlConnection sql = new SqlConnection(@"Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\Database1.mdf;Integrated Security=True;Connect Timeout=30");
SqlCommand cmd = new SqlCommand("delete from [Table]", sql);
sql.Open();
cmd.ExecuteNonQuery();
sql.Close();
listView1.Items.Clear();