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;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
string strCon = "Data Source =.\\sqlexpress;Initial Catalog=XSGL;Integrated Security=True";
public Form1()
{
InitializeComponent();
}
private void label1_Click(object sender, EventArgs e)
{
}
private void label2_Click(object sender, EventArgs e)
{
}
private void label3_Click(object sender, EventArgs e)
{
}
private void Form1_Load(object sender, EventArgs e)
{
try
{
SqlConnection mycon = new SqlConnection(strCon);
mycon.Open();
string strSel = "select Cno as 課程號,Cname as 課程名,Ccode as 學(xué)分 from T_Course";
SqlDataAdapter myda = new SqlDataAdapter(strSel, mycon);
DataTable dt = new DataTable();
myda.Fill(dt);
dataGridView1.DataSource = dt;
mycon.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
if (button1.Text == "增加")
{
try
{
// string strCon = "Data Source =.\\sqlexpress;Initial Catalog=XSGL;Integrated Security=True";
string cno = textcno.Text;
string cname = textcname.Text;
string Ccode = textcode.Text;
SqlConnection mycon = new SqlConnection(strCon);
mycon.Open();
//string StrUpd = "update T_Student set sage='" + sage + "' where sname='" + sname + "'";
string strins = "insert into T_course(cno,cname,Ccode) values ('" + cno + "','" + cname + "','" + Ccode + "')";
//string StrUpd = "insert into T_Student(Sno,Sname,Ssex,Sage,Sdept) values ('"+sno+"','"+sname+"','"+ssex+"','"+sage+"','"+sdept+"')";
SqlCommand mycmd = new SqlCommand(strins, mycon);
mycmd.ExecuteNonQuery();
string strSel = "select Cno as 課程號,Cname as 課程名,Ccode as 學(xué)分 from T_Course";
SqlDataAdapter myda = new SqlDataAdapter(strSel, mycon);
DataTable dt = new DataTable();
myda.Fill(dt);
dataGridView1.DataSource = dt;
mycon.Close();
MessageBox.Show("增加成功啊楚!");
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
else
{
try
{
// string strCon = "Data Source =.\\sqlexpress;Initial Catalog=XSGL;Integrated Security=True";
string cno = textcno.Text;
string cname = textcname.Text;
string Ccode = textcode.Text;
SqlConnection mycon = new SqlConnection(strCon);
mycon.Open();
string StrUpd = "update T_course set cname='" + cname + "' , Ccode='" + Ccode + "' where cno='" + cno + "'";
//string strins = "insert into T_course(cno,cname,Ccode) values ('" + cno + "','" + cname + "','" + Ccode + "')";
//string StrUpd = "insert into T_Student(Sno,Sname,Ssex,Sage,Sdept) values ('"+sno+"','"+sname+"','"+ssex+"','"+sage+"','"+sdept+"')";
SqlCommand mycmd = new SqlCommand(StrUpd, mycon);
mycmd.ExecuteNonQuery();
string strSel = "select Cno as 課程號,Cname as 課程名,Ccode as 學(xué)分 from T_Course";
SqlDataAdapter myda = new SqlDataAdapter(strSel, mycon);
DataTable dt = new DataTable();
myda.Fill(dt);
dataGridView1.DataSource = dt;
mycon.Close();
MessageBox.Show("修改成功澈侠!");
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
}
private void 修改ToolStripMenuItem_Click(object sender, EventArgs e)
{
if (dataGridView1.SelectedRows.Count > 0)
{
textcno.Text = dataGridView1.SelectedRows[0].Cells[0].Value.ToString();
textcname.Text = dataGridView1.SelectedRows[0].Cells[1].Value.ToString();
textcode.Text = dataGridView1.SelectedRows[0].Cells[2].Value.ToString();
button1.Text = "修改";
textcno.Enabled = false;
}
}
private void 刪除ToolStripMenuItem_Click(object sender, EventArgs e)
{
try
{
if (DialogResult.Yes == MessageBox.Show("確定要刪除這條記錄嗎锨天?","", MessageBoxButtons.YesNo))
{
// string strCon = "Data Source =.\\sqlexpress;Initial Catalog=XSGL;Integrated Security=True";
//string cno = textcno.Text;
//string cname = textcname.Text;
//string Ccode = textcode.Text;
SqlConnection mycon = new SqlConnection(strCon);
mycon.Open();
string cno = dataGridView1.SelectedRows[0].Cells[0].Value.ToString();
string strins = "delete from T_course where cno ='"+cno+"'";
//string StrUpd = "update T_course set cname='" + cname + "' , Ccode='" + Ccode + "' where cno='" + cno + "'";
//string strins = "insert into T_course(cno,cname,Ccode) values ('" + cno + "','" + cname + "','" + Ccode + "')";
//string StrUpd = "insert into T_Student(Sno,Sname,Ssex,Sage,Sdept) values ('"+sno+"','"+sname+"','"+ssex+"','"+sage+"','"+sdept+"')";
SqlCommand mycmd = new SqlCommand(strins, mycon);
mycmd.ExecuteNonQuery();
string strSel = "select Cno as 課程號,Cname as 課程名,Ccode as 學(xué)分 from T_Course";
SqlDataAdapter myda = new SqlDataAdapter(strSel, mycon);
DataTable dt = new DataTable();
myda.Fill(dt);
this.dataGridView1.DataSource = dt;
mycon.Close();
MessageBox.Show("刪除成功否过!");
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
}
}
第三次實驗課
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
- 文/潘曉璐 我一進店門怀大,熙熙樓的掌柜王于貴愁眉苦臉地迎上來纱兑,“玉大人,你說我怎么就攤上這事化借∏鄙鳎” “怎么了?”我有些...
- 文/不壞的土叔 我叫張陵蓖康,是天一觀的道長铐炫。 經(jīng)常有香客問我,道長蒜焊,這世上最難降的妖魔是什么倒信? 我笑而不...
- 正文 為了忘掉前任,我火速辦了婚禮泳梆,結(jié)果婚禮上鳖悠,老公的妹妹穿的比我還像新娘。我一直安慰自己优妙,他們只是感情好乘综,可當我...
- 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著套硼,像睡著了一般卡辰。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上邪意,一...
- 文/蒼蘭香墨 我猛地睜開眼森渐,長吁一口氣:“原來是場噩夢啊……” “哼做入!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起同衣,我...
- 正文 年R本政府宣布河劝,位于F島的核電站,受9級特大地震影響矛紫,放射性物質(zhì)發(fā)生泄漏赎瞎。R本人自食惡果不足惜,卻給世界環(huán)境...
- 文/蒙蒙 一颊咬、第九天 我趴在偏房一處隱蔽的房頂上張望务甥。 院中可真熱鬧,春花似錦贪染、人聲如沸缓呛。這莊子的主人今日做“春日...
- 文/蒼蘭香墨 我抬頭看了看天上的太陽哟绊。三九已至,卻和暖如春痰憎,著一層夾襖步出監(jiān)牢的瞬間票髓,已是汗流浹背。 一陣腳步聲響...
推薦閱讀更多精彩內(nèi)容
- 【蝴蝶效應(yīng)】 蝴蝶效應(yīng):上個世紀70年代吊骤,美國一個名叫洛倫茲的氣象學(xué)家在解釋空氣系統(tǒng)理論時說缎岗,亞馬遜雨林一只蝴蝶...
- 怎樣反思自己的教學(xué)——學(xué)習(xí)杜威《我們怎樣思維》有感 2015-01-13 14:56:52 來源:普寧市第三中學(xué)網(wǎng)...
- 個人增值,這個主題白粉,一開始拿到手传泊,感覺好大鼠渺,但是后來經(jīng)過思考,任何行為都要現(xiàn)設(shè)目標眷细,再行動拦盹,沒有目標的行為就好比射...
- 2017.10.13 1.今年我們班級少了4個人掌敬,降級了。我們組少了兩個池磁,前一組也少了兩個奔害,于是,我們這兩組合并了...
- 在《射雕英雄傳》中作者詮釋了俠的精髓——俠之大者地熄,為國為民华临。從此點出發(fā),這是一部頌歌,這其中的每一個正面形象都光輝...