C#.Net Microsoft Report Viewer.
using
System.Linq;
using
System.Text;
using
System.Windows.Forms;
using
System.Data.SqlClient;
namespace Report_stu
{
public partial class Form1 : Form
{
public
Form1()
{
InitializeComponent();
}
private
void Form1_Load(object
sender, EventArgs e)
{
// TODO:
This line of code loads data into the 'ICTPTDataSet.sturegfull' table. You can
move, or remove it, as needed.
this.sturegfullTableAdapter.Fill(this.ICTPTDataSet.sturegfull);
this.reportViewer1.RefreshReport();
}
private
string connectionstring = "Data Source=DESKTOP-31HBTKT\\SQLEXPRESS; Initial
Catalog=ICTPT;Integrated Security=True";
private
void button1_Click(object
sender, EventArgs e)
{
if
(textBox1.Text == "")
{
MessageBox.Show("Please Enter Student ID");
}
else
{
try
{
SqlConnection
con = new SqlConnection(connectionstring);
con.Open();
SqlCommand
cmd = new SqlCommand("SELECT stuid FROM sturegfull WHERE stuid= '"
+ this.textBox1.Text + "'",
con);
SqlDataReader
ExRer = cmd.ExecuteReader();
int
count = 0;
while
(ExRer.Read())
{
count = count + 1;
}
if
(count == 1)
{
this.sturegfullTableAdapter.FillBy(this.ICTPTDataSet.sturegfull,
textBox1.Text);
this.reportViewer1.RefreshReport();
}
else
if (count > 1)
{
MessageBox.Show("Duplicate
ID..Access denied");
}
else
MessageBox.Show("Invalid
Student ID ");
textBox1.Text = "";
con.Close();
}
catch
(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
}
}
0 Comments