TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Naidu AMMAN
NA
37
35.2k
how to generate grid to excel formate
Apr 23 2015 6:25 AM
namespace frmroutecodedtls
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
SqlCommand cmd;
SqlConnection con;
SqlDataAdapter da;
DataSet ds;
private void btnSave_Click(object sender, EventArgs e)
{
#region SaveToDB
try
{
con = new SqlConnection("Data Source=SUMANTH-PC\\SQLEXPRESS;Initial Catalog=model;Integrated Security=True");
cmd = new SqlCommand("SP_tbl_routecodedtls", con) { CommandType = CommandType.StoredProcedure };
con.Open();
cmd.Parameters.AddWithValue("@rcode", txt_rcode.Text);
cmd.Parameters.AddWithValue("@scode", txt_scode.Text);
cmd.Parameters.AddWithValue("@sname", txt_sname.Text);
cmd.Parameters.AddWithValue("@nkms", txt_nkms.Text);
cmd.Parameters.AddWithValue("@fare", txt_fare.Text);
cmd.Parameters.AddWithValue("@sno", txt_sno.Text);
cmd.Parameters.AddWithValue("@rfstop", txt_rfstop.Text);
cmd.Parameters.AddWithValue("@type", "save");
cmd.Parameters.Add("@output_sname", SqlDbType.Char, (500));
cmd.Parameters["@output_sname"].Direction = ParameterDirection.Output;
cmd.Parameters.Add("@output_nkms", SqlDbType.Char, (500));
cmd.Parameters["@output_nkms"].Direction = ParameterDirection.Output;
cmd.Parameters.Add("@output_fare", SqlDbType.Char, (500));
cmd.Parameters["@output_fare"].Direction = ParameterDirection.Output;
cmd.Parameters.Add("@output_sno", SqlDbType.Char, (500));
cmd.Parameters["@output_sno"].Direction = ParameterDirection.Output;
cmd.Parameters.Add("@output_rfstop", SqlDbType.Char, (500));
cmd.Parameters["@output_rfstop"].Direction = ParameterDirection.Output;
cmd.ExecuteNonQuery();
con.Close();
MessageBox.Show("Data Saved Successfully");
BindToDatagrid();
clearFields();
}
#endregion
catch (Exception exe)
{
MessageBox.Show(exe.Message.ToString());
}
}
protected void clearFields()
{
txt_rcode.Text = string.Empty;
txt_scode.Text = string.Empty;
txt_sname.Text = string.Empty;
txt_nkms.Text = string.Empty;
txt_fare.Text = string.Empty;
txt_sno.Text = string.Empty;
txt_rfstop.Text = string.Empty;
}
private void btnClear_Click(object sender, EventArgs e)
{
clearFields();
}
private void btnClose_Click(object sender, EventArgs e)
{
this.Close();
}
private void btnShow_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("Data Source=SUMANTH-PC\\SQLEXPRESS;Initial Catalog=model;Integrated Security=True");
SqlCommand cmd = new SqlCommand("SP_tbl_routecodedtls", con) { CommandType = CommandType.StoredProcedure };
con.Open();
cmd.Parameters.AddWithValue("@rcode", txt_rcode.Text);
cmd.Parameters.AddWithValue("@scode", txt_scode.Text);
cmd.Parameters.AddWithValue("@sname", 0);
cmd.Parameters.AddWithValue("@nkms", 0);
cmd.Parameters.AddWithValue("@fare", 0);
cmd.Parameters.AddWithValue("@sno", 0);
cmd.Parameters.AddWithValue("@rfstop", 0);
cmd.Parameters.AddWithValue("@type", "show");
cmd.Parameters.Add("@output_sname", SqlDbType.Char, (500));
cmd.Parameters["@output_sname"].Direction = ParameterDirection.Output;
cmd.Parameters.Add("@output_nkms", SqlDbType.Char, (500));
cmd.Parameters["@output_nkms"].Direction = ParameterDirection.Output;
cmd.Parameters.Add("@output_fare", SqlDbType.Char, (500));
cmd.Parameters["@output_fare"].Direction = ParameterDirection.Output;
cmd.Parameters.Add("@output_sno", SqlDbType.Char, (500));
cmd.Parameters["@output_sno"].Direction = ParameterDirection.Output;
cmd.Parameters.Add("@output_rfstop", SqlDbType.Char, (500));
cmd.Parameters["@output_rfstop"].Direction = ParameterDirection.Output;
cmd.ExecuteNonQuery();
System.String sname = (string)cmd.Parameters["@output_sname"].Value;
System.String nkms = (string)cmd.Parameters["@output_nkms"].Value;
System.String fare = (string)cmd.Parameters["@output_fare"].Value;
System.String sno = (string)cmd.Parameters["@output_sno"].Value;
System.String rfstop = (string)cmd.Parameters["@output_rfstop"].Value;
txt_sname.Text = sname;
txt_nkms.Text = nkms;
txt_fare.Text = fare;
txt_sno.Text = sno;
txt_rfstop.Text = rfstop;
con.Close();
}
private void BindToDatagrid()
{
ds = new DataSet();
con = new SqlConnection("Data Source=SUMANTH-PC\\SQLEXPRESS;Initial Catalog=model;Integrated Security=True");
con.Open();
cmd = new SqlCommand("select * from tbl_routecodedtls", con) { CommandType = CommandType.Text };
cmd.ExecuteNonQuery();
da = new SqlDataAdapter(cmd);
da.Fill(ds, "routeCodedtls");
dataGridView1.DataSource = ds.Tables["routeCodedtls"].DefaultView;
con.Close();
}
private void Form1_Load(object sender, EventArgs e)
{
BindToDatagrid();
//DataGridViewButtonColumn btnDelete = new DataGridViewButtonColumn();
//btnDelete.Name = "btnDelete";
//btnDelete.Text = "Delete";
//btnDelete.Width = 100;
//btnDelete.HeaderText = "DeleteRow";
//dataGridView1.Columns.Add(btnDelete);
}
private void dataGridView1_SelectionChanged(object sender, EventArgs e)
{
if (dataGridView1.SelectedRows.Count > 0)
{
txt_rcode.Text = dataGridView1.SelectedRows[0].Cells[0].Value.ToString();
}
}
private void btnDelete_Click(object sender, EventArgs e)
{
if (dataGridView1.SelectedRows.Count > 0)
{
dataGridView1.Rows.RemoveAt(dataGridView1.SelectedRows[0].Index);
}
else
MessageBox.Show("Please select any row");
}
}
}
Reply
Answers (
1
)
Summerize timespane in datagridview, using ms access db
Crystal Reprt Faild Error