using (OracleConnection conn = new OracleConnection(str))
{
conn.Open();
string xz = "select*from tbl_autoplay_list";
OracleDataAdapter oda = new OracleDataAdapter();
OracleCommand insert = new OracleCommand(xz,conn);
OracleCommandBuilder ob = new OracleCommandBuilder(oda);
oda.SelectCommand = insert;
DataSet ds = new DataSet();
int count = oda.Fill(ds, "tbl_autoplay_list");
if (count >= 0)
{
DataRow dr = ds.Tables["tbl_autoplay_list"].NewRow();
dr["FACT_NO"] = comboBox1.Text;
dr["ITEM_NO"] = textBox1.Text;
dr["DEVICE_ID"] = comboBox2.Text;
dr["INTERVAL"] = textBox2.Text;
dr["STATUS"] = "Y";
dr["PLAY_URL"] = textBox3.Text;
dr["PLAY_TIMERANGE1"] = plt;
dr["PLAY_TIMERANGE2"] = "";
dr["PLAY_TIMERANGE3"] = "";
dr["PLAY_TIMERANGE4"] = "";
dr["PLAY_TIMERANGE5"] = "";
dr["EXPECT_TIMERANGE1"] = ext;
dr["EXPECT_TIMERANGE2"] = "";
dr["EXPECT_TIMERANGE3"] = "";
dr["EXPECT_TIMERANGE4"] = "";
dr["EXPECT_TIMERANGE5"] = "";
dr["MEMO"] = textBox4.Text;
ds.Tables["tbl_autoplay_list"].Rows.Add(dr);
oda.Update(ds, "tbl_autoplay_list");
}
ds.Clear();
MessageBox.Show("新增成功"); }
{
conn.Open();
string xz = "select*from tbl_autoplay_list";
OracleDataAdapter oda = new OracleDataAdapter();
OracleCommand insert = new OracleCommand(xz,conn);
OracleCommandBuilder ob = new OracleCommandBuilder(oda);
oda.SelectCommand = insert;
DataSet ds = new DataSet();
int count = oda.Fill(ds, "tbl_autoplay_list");
if (count >= 0)
{
DataRow dr = ds.Tables["tbl_autoplay_list"].NewRow();
dr["FACT_NO"] = comboBox1.Text;
dr["ITEM_NO"] = textBox1.Text;
dr["DEVICE_ID"] = comboBox2.Text;
dr["INTERVAL"] = textBox2.Text;
dr["STATUS"] = "Y";
dr["PLAY_URL"] = textBox3.Text;
dr["PLAY_TIMERANGE1"] = plt;
dr["PLAY_TIMERANGE2"] = "";
dr["PLAY_TIMERANGE3"] = "";
dr["PLAY_TIMERANGE4"] = "";
dr["PLAY_TIMERANGE5"] = "";
dr["EXPECT_TIMERANGE1"] = ext;
dr["EXPECT_TIMERANGE2"] = "";
dr["EXPECT_TIMERANGE3"] = "";
dr["EXPECT_TIMERANGE4"] = "";
dr["EXPECT_TIMERANGE5"] = "";
dr["MEMO"] = textBox4.Text;
ds.Tables["tbl_autoplay_list"].Rows.Add(dr);
oda.Update(ds, "tbl_autoplay_list");
}
ds.Clear();
MessageBox.Show("新增成功"); }
{
try
{
.....
}
catch(Exception ex)
{}
加了try catch 沒捕獲到異常!!!
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.Collections;
using System.Data.OracleClient;
//using System.Text;
namespace WindowsFormsApplication2
{
public partial class 新增 : Form
{
string a;
string plt;
string ext;
public 新增()
{
InitializeComponent();
} private void Form2_Load(object sender, EventArgs e)
{
string str = "server=db_web_dg;uid=py3web;pwd=py3web";
string ocbb1 = "SELECT Distinct(fact_no) from tbl_autoplay_list";
string ocbb2 = "SELECT Distinct(DEVICE_ID) from tbl_autoplay_list";
string ocbb3 = "select max(item_no) maxvalues from tbl_autoplay_list";
OracleConnection conn = new OracleConnection(str);
conn.Open();
OracleDataAdapter oda1 = new OracleDataAdapter(ocbb1, conn);
OracleDataAdapter oda2 = new OracleDataAdapter(ocbb2, conn);
OracleDataAdapter oda3 = new OracleDataAdapter(ocbb3, conn);
DataSet ds1 = new DataSet();
DataSet ds2 = new DataSet();
DataSet ds3 = new DataSet();
oda1.Fill(ds1, "tbl_autoplay_list");
oda2.Fill(ds2, "tbl_autoplay_list");
oda3.Fill(ds3, "tbl_autoplay_list");
conn.Close();
DataTable dt1 = new DataTable();
DataTable dt2 = new DataTable();
DataTable dt3 = new DataTable();
dt1 = ds1.Tables["tbl_autoplay_list"];
dt1.Rows.Add("請選擇");
dt2 = ds2.Tables["tbl_autoplay_list"];
dt2.Rows.Add("請選擇");
//dt3 = ds3.Tables["tbl_autoplay_list"];
comboBox1.DataSource = dt1;
comboBox2.DataSource = dt2;
comboBox1.DisplayMember = "fact_no";
comboBox2.DisplayMember = "device_id";
comboBox1.Text = "請選擇";
comboBox2.Text = "請選擇";
comboBox3.Text = "--";
comboBox4.Text = "--";
comboBox5.Text = "--";
comboBox6.Text = "--";
comboBox7.Text = "--";
comboBox8.Text = "--";
comboBox9.Text = "--";
comboBox10.Text = "--"; a = ds3.Tables[0].Rows[0][0].ToString();
textBox1.Text = Convert.ToString(Convert.ToSingle(a) + 1);
} private void textBox2_KeyPress(object sender, KeyPressEventArgs e)
{
//if (!(Char.IsNumber(e.KeyChar)) && e.KeyChar != (char)13 && e.KeyChar != (char)8)
//{
// e.Handled = true;
//}
} private void button1_Click(object sender, EventArgs e) //新增!
{ //獲取fato_no欄位值
if (comboBox1.Text == "請選擇")
{
MessageBox.Show("請選擇FACTO_N0", "錯誤提示!");
return;
} //獲取device_id欄位值
if (comboBox2.Text == "請選擇")
{
MessageBox.Show("請選擇DEVICE_ID", "錯誤提示!");
return;
}
//獲取interval欄位值
if (textBox2.Text.Trim() != "")
{
if (Convert.ToSingle(textBox2.Text) > 100)
{
MessageBox.Show("您輸入的INTERVAL數字過大!", "錯誤提示!");
return;
} }
else
{
MessageBox.Show("請輸入interval值!", "錯誤提示!");
return;
} //獲取play_url欄位值
if (textBox3.Text == "")
{
MessageBox.Show("請輸入PLAY_URL", "錯誤提示!");
return;
}
//獲取PLAY_TIMERANGE1欄位值
if (comboBox3.Text != "--" || comboBox4.Text != "--"
|| comboBox5.Text != "--" || comboBox6.Text != "--")
{
if (Convert.ToSingle(comboBox3.Text) < Convert.ToSingle(comboBox5.Text))
{
plt = String.Format(",{0}:{1}-{2}:{3}", comboBox3.Text,
comboBox4.Text, comboBox5.Text, comboBox6.Text);
}
else
{
MessageBox.Show("PLAY_TIMERANGE1輸入有誤!請檢查!", "錯誤提示!");
return;
}
}
else
{
MessageBox.Show("PLAY_TIMERANGE1輸入不完整!", "錯誤提示!");
return;
} //獲取except_TIMERANGE1欄位值
if (comboBox3.Text != "--" || comboBox4.Text != "--"
|| comboBox5.Text != "--" || comboBox6.Text != "--")
{
if (Convert.ToSingle(comboBox3.Text) < Convert.ToSingle(comboBox5.Text))
{
ext = String.Format(",{0}:{1}-{2}:{3}", comboBox10.Text,
comboBox9.Text, comboBox8.Text, comboBox7.Text);
}
else
{
MessageBox.Show("EXCEPT_TIMERANGE1輸入有誤!請檢查!", "錯誤提示!");
return;
}
}
else
{
MessageBox.Show("EXCEPT_TIMERANGE1輸入不完整!", "錯誤提示!");
return;
}
string str = "server=db_web_dg;uid=py3web;pwd=py3web";
using (OracleConnection conn = new OracleConnection(str))
{
try
{
conn.Open();
string xz = "select*from tbl_autoplay_list"; OracleDataAdapter oda = new OracleDataAdapter();
OracleCommand insert = new OracleCommand(xz, conn);
OracleCommandBuilder ob = new OracleCommandBuilder(oda);
oda.SelectCommand = insert;
DataSet ds = new DataSet();
int count = oda.Fill(ds, "tbl_autoplay_list");
if (count >= 0)
{
DataRow dr = ds.Tables["tbl_autoplay_list"].NewRow();
dr["FACT_NO"] = comboBox1.Text;
dr["ITEM_NO"] = textBox1.Text;
dr["DEVICE_ID"] = comboBox2.Text;
dr["INTERVAL"] = textBox2.Text;
dr["STATUS"] = "Y";
dr["PLAY_URL"] = textBox3.Text;
dr["PLAY_TIMERANGE1"] = plt;
dr["PLAY_TIMERANGE2"] = "";
dr["PLAY_TIMERANGE3"] = "";
dr["PLAY_TIMERANGE4"] = "";
dr["PLAY_TIMERANGE5"] = "";
dr["EXPECT_TIMERANGE1"] = ext;
dr["EXPECT_TIMERANGE2"] = "";
dr["EXPECT_TIMERANGE3"] = "";
dr["EXPECT_TIMERANGE4"] = "";
dr["EXPECT_TIMERANGE5"] = "";
dr["MEMO"] = textBox4.Text;
ds.Tables["tbl_autoplay_list"].Rows.Add(dr);
oda.Update(ds, "tbl_autoplay_list");
}
ds.Clear();
MessageBox.Show("新增成功");
}
catch (Exception ex)
{
throw ex;
}
}
} }}