C#警告不存在的用户ID [英] C# Warning for non-exist user ID
问题描述
您好,
我有一个带有SQL Server的C#Windows表单项目。我有一张开票表格。在此表单中,用户打开服务台的票证。我想要做的是,当用户打开票证时,必须对不存在的用户的情况发出警告,在这种情况下必须防止票证。例如,我想打开一张票,我为kullaniciID输入21,但是我的用户表中不存在此ID,并且必须阻止此记录,当然还有一条消息。我怎么能这样做?
感谢您的帮助。我的代码块如下:
Hello,
I have a C# Windows form Project with SQL Server. I have a ticket opening form. At this form, user opens a ticket for help desk. What I want to do is, while user opening a ticket, there must be a warning for cases non-exist users, at this case the ticket must be prevented. For example, I want to open a ticket and I enter 21 for kullaniciID, but this ID does not exist at my user table and this record must be prevented, of course with a message. How can I do that?
Thanks for your help. My code block is below:
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;
namespace ITHelpDeskProject
{
public partial class CgrKydOlstr : Form
{
public CgrKydOlstr()
{
InitializeComponent();
}
private void CgrKydOlstr_Load(object sender, EventArgs e)
{
CMBBOXproblemTur.Items.Add("Donanım Arızası");
CMBBOXproblemTur.Items.Add("Yazılım Problemi");
CMBBOXproblemTur.Items.Add("Network Problemi");
}
private void BTNkaydet_Click(object sender, EventArgs e)
{
SqlConnection baglanti = new SqlConnection("Data Source=EMREY\\MS_SQLSERVER;Initial Catalog=ITHelpDeskProjesi;Integrated Security=True");
baglanti.Open();
string SonKayitID;
DateTime dt = Convert.ToDateTime(DTPCKRkayitTarih.Value.ToString("yyyy-MM-dd"));
String zaman = dt.ToString("yyyy-MM-dd hh:mm:ss");
SqlCommand cmd = new SqlCommand("INSERT INTO tblKayit(kullaniciID, bilgisayarID, yaziciID, problemTur, kayitTarihi) VALUES(@kullaniciID, @bilgisayarID, @yaziciID, @problemTur, @kayitTarihi); select scope_identity()");
cmd.Parameters.AddWithValue("@kullaniciID", TXTBOXkulID.Text);
cmd.Parameters.AddWithValue("@bilgisayarID", TXTBOXbilID.Text);
cmd.Parameters.AddWithValue("@yaziciID", TXTBOXyaziciID.Text);
cmd.Parameters.AddWithValue("@problemTur", CMBBOXproblemTur.Text);
cmd.Parameters.AddWithValue("@kayitTarihi", dt);
cmd.Connection = baglanti;
SonKayitID = cmd.ExecuteScalar().ToString();
MessageBox.Show("Yardım masası çağrı kaydınız oluşturulmuştur. Çağrı kaydınız hakkında bilgi almak için kullanabileceğiniz referans numaranız : " + SonKayitID);
baglanti.Close();
CgrKydOlstr_Load(sender, e);
}
private void BTNanaSayfa_Click(object sender, EventArgs e)
{
personelAnaMenu prsana = new personelAnaMenu();
prsana.Show();
this.Hide();
}
private void BTNsistemdenCik_Click(object sender, EventArgs e)
{
this.Close();
}
private void CgrKydOlstr_FormClosing(object sender, FormClosingEventArgs e)
{
Application.Exit();
}
}
}
[edit]已添加代码块 - OriginalGriff [/ edit]
[edit]Code block added - OriginalGriff[/edit]
推荐答案
这篇关于C#警告不存在的用户ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!