پایگاه داده در سی شارپ(جستجو)
سلام دوستان عزیز.
من دارم یک پروژه فروشگاه با سی شارپ درست میکنم.حذف و اضافه و ویرایش کالا رو میدونم اما نحوه جستجو در پایگاه داده و گزارش گیری رو بلد نیستم.از شما سروران خواهش میکنم اگه بلدین مرا راهنمایی کنید.خیلی ضروریه!درضمن منظور از گزارش گیری رو هم نمیدونم چیه!یعنی باید یه دکمه بزارم که وقتی روش کلیک میکنیم تمام اطلاعات موجود در پایگاه داده رو بده؟منطور همینه؟ممنون.
:n25:
اینم کدهای نوشته شده توسط خودم برای اضافه کردن و حذف و ویرایش!
کد:
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 project
{
public partial class Form1 : Form
{
SqlConnection con;
SqlCommand cmd;
SqlDataAdapter da;
public Form1()
{
InitializeComponent();
this.con = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\data.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True");
this.cmd = new SqlCommand();
this.da = new SqlDataAdapter();
this.cmd.Connection = con;
this.da.SelectCommand = cmd;
}
private void button_New_Click(object sender, EventArgs e)
{
this.con.Open();
this.cmd.CommandText = "insert into table1 (name,family) values ('"+textBox_Name.Text+"','mohammad')";
this.cmd.ExecuteNonQuery();
this.con.Close();
}
private void button_Edit_Click(object sender, EventArgs e)
{
this.con.Open();
this.cmd.CommandText = "update person set pfname=N'" + textBox_Name.Text + "',plname=N'" + textBox_Tell.Text + "',ptell=''"+textBox_Tell.Text+",paddress=N'" + textBox_Address.Text + "' where pid=" + int.Parse(textBox_Id.Text);
this.cmd.ExecuteNonQuery();
this.con.Close();
}
private void button_Delete_Click(object sender, EventArgs e)
{
this.con.Open();
this.cmd.CommandText="Delete from table1 where id=" + int.Parse(textBox_Id.Text);
this.cmd.ExecuteNonQuery();
this.con.Close();
}
private void textBox_Id_TextChanged(object sender, EventArgs e)
{
}
private void button_Exit_Click(object sender, EventArgs e)
{
this.Close();
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
}