【发布时间】:2018-06-08 23:39:05
【问题描述】:
对不起,如果这是一个愚蠢的问题,但你能帮我添加一些代码到我的应用程序中,当有人成功添加到表中时生成一个 MessageBox,并且每当生成一个阻止所需信息的异常时生成另一个 MessageBox被添加到表中?我的代码如下:
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.Sql;
using System.Data.SqlClient;
namespace WindowsFormsApp1
{
public partial class AddJob : Form
{
public AddJob()
{
InitializeComponent();
}
private void AddJob_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
SqlCommand cmd;
SqlConnection con;
SqlDataAdapter da;
con = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\richard.schade\Desktop\IKJobs\WindowsFormsApp1\ikData.mdf;Integrated Security=True");
con.Open();
cmd = new SqlCommand("INSERT INTO openJobs (jobTitle, jobDescription, dateOpened, jobsiteLink, jobLocation) VALUES (@jobTitle, @jobDescription, @dateOpened, @jobsiteLink, @jobLocation)", con);
cmd.Parameters.AddWithValue("@jobTitle", textBox1.Text);
cmd.Parameters.AddWithValue("@jobDescription", textBox5.Text);
cmd.Parameters.AddWithValue("@dateOpened", textBox4.Text);
cmd.Parameters.AddWithValue("@jobsiteLink", textBox3.Text);
cmd.Parameters.AddWithValue("@jobLocation", textBox2.Text);
cmd.ExecuteNonQuery();
}
}
}
感谢您的帮助,我已经从这个论坛学到了很多东西。
【问题讨论】:
-
在 WinForms 中使用
MessageBox.Show()显示消息框。使用该功能,您会很快找到答案 -
感谢您的意见,这里是全新的。