1
그림 상자를 설정하는 방법이 궁금하고 이미지 2 개가 표시됩니다. 값 트루 이미지 번호 1에서 거짓 값에, 이미지 번호 2. 내가 프로그래밍 멍청한 놈이야 ... 내 레코드 이름이 "oddal"데이터 형식입니다 "비트"여기데이터베이스에서 값이 True 또는 False 일 때 이미지를 표시하는 방법
내 코드입니다
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
SqlConnection cn = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\MSI\Documents\Visual Studio 2010\Projects\Baza z własnymi batonami\Baza z własnymi batonami\Database1.mdf;Integrated Security=True;User Instance=True");
SqlCommand cmd = new SqlCommand();
SqlDataReader dr;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
cmd.Connection = cn;
pokazliste();
}
private void button1_Click(object sender, EventArgs e)
{
if (textid.Text != "" & textimie.Text != "")
{
cn.Open();
cmd.CommandText = "Insert into Table1 (id,imie) values('" + textid.Text + "','" + textimie.Text + "')";
cmd.ExecuteNonQuery();
cmd.Clone();
MessageBox.Show("Wpis Wprowadzony","Vindykacja by Brzoska");
cn.Close();
textid.Text = "";
textimie.Text = "";
pokazliste();
}
}
private void pokazliste()
{
listBox1.Items.Clear();
listBox2.Items.Clear();
cn.Open();
cmd.CommandText = "Select * From Table1";
dr = cmd.ExecuteReader();
if (dr.HasRows)
{
while(dr.Read())
{
listBox1.Items.Add(dr[0].ToString());
listBox2.Items.Add(dr[1].ToString());
}
}
cn.Close();
}
private void listBox2_SelectedIndexChanged(object sender, EventArgs e)
{
ListBox l = sender as ListBox;
if (l.SelectedIndex != -1)
{
listBox1.SelectedIndex = l.SelectedIndex;
listBox2.SelectedIndex = l.SelectedIndex;
textid.Text = listBox1.SelectedItem.ToString();
textimie.Text = listBox2.SelectedItem.ToString();
}
}
private void button2_Click(object sender, EventArgs e)
{
if (textid.Text != "" & textimie.Text != "" & listBox1.SelectedIndex!=-1)
{
cn.Open();
cmd.CommandText = "delete from Table1 where id='" + listBox1.SelectedItem.ToString() + "' and imie= '" + listBox2.SelectedItem.ToString() + "'";
cmd.ExecuteNonQuery();
cn.Close();
MessageBox.Show("Wpis Uaktualniony", "Vindykacja by Brzoska");
pokazliste();
textid.Text = "";
textimie.Text = "";
}
}
private void button3_Click(object sender, EventArgs e)
{
if (textid.Text != "" & textimie.Text != "")
{
cn.Open();
cmd.CommandText = "Update Table1 set id='" + textid.Text + "', imie= '" + textimie.Text + "'Where id'" + textid.Text + "'and imie= '" + textimie.Text + "'";
cmd.ExecuteNonQuery();
cn.Close();
MessageBox.Show("Wpis Usuniety", "Vindykacja by Brzoska");
pokazliste();
textid.Text = "";
textimie.Text = "";
}
}
private void pictureBox1_Click(object sender, EventArgs e)
{
}
}
}
먼저 코드가 SQL Injection에 열려 있습니다. 쿼리에 매개 변수를 사용하십시오. [이 기사 참조] (http://csharp-station.com/Tutorial/AdoDotNet/Lesson06) –
선생님도 똑같이 말하지만 그는 괜찮을 것이라고 말합니다. 하지만 패스하고 싶으면이 그림을 써야합니다. 나는이 기사를 읽는다. 그러나 나는 정말로 그것을 이해하지 않는다. .. – user2157657