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
prinze shilz
NA
5
5.4k
Ristrict GridView Duplicates
May 11 2012 3:38 AM
Hello Friends,
I m designing an application of a restaurant but I m facing a problem, I want to restrict duplicate values in GridView. For example: I Want if a user select particular item form LISTVIEW twice item will not add but quantity increase.
Note
:I m inserting rows in
Invoice
Table when retrieving rows in Gridview from
Items
Table;
Please help me, I also attached GUI and Table snaps and sourceCode, Thanks
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication8
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
OleDbConnection con;
OleDbDataAdapter dAdapter;
OleDbCommandBuilder cBuilder;
DataTable dTable;
//DataSet ds;
OleDbCommand cmd;
DataView myDataView;
//string query;
private void button1_Click(object sender, EventArgs e)
{
int index = listView1.SelectedItems[0].Index;
con = new OleDbConnection(@"Provider=Microsoft.ACE.Oledb.12.0;Data Source=D:\\gridview.accdb");
cmd = new OleDbCommand();
cmd.CommandText = "Select * from ITEMS";
dAdapter = new OleDbDataAdapter(cmd.CommandText, con);
dTable = new DataTable();
cBuilder = new OleDbCommandBuilder(dAdapter);
cBuilder.QuotePrefix = "[";
cBuilder.QuoteSuffix = "]";
myDataView = dTable.DefaultView;
dAdapter.Fill(dTable);
dataGridView1.Rows.Add(dTable.Rows[index][0], dTable.Rows[index][1], dTable.Rows[index][2], dTable.Rows[index][3]);
cmd = new OleDbCommand();
cmd.CommandText = string.Format("INSERT INTO INVOICE VALUES('{0}','{1}','{2}','{3}')", dataGridView1.Rows[index].Cells[0].Value, dataGridView1.Rows[index].Cells[1].Value, dataGridView1.Rows[index].Cells[2].Value, dataGridView1.Rows[index].Cells[3].Value);
cmd.Connection = con;
con.Open();
cmd.ExecuteNonQuery();
MessageBox.Show("ORDER DELIVERED");
con.Close();
}
private void Form1_Load(object sender, EventArgs e)
{
DataGridViewTextBoxColumn col = new DataGridViewTextBoxColumn();
col.HeaderText = "ID";
col.ValueType = typeof(int);
dataGridView1.Columns.Add(col);
col = new DataGridViewTextBoxColumn();
col.HeaderText = "ITEM";
col.ValueType = typeof(String);
dataGridView1.Columns.Add(col);
col = new DataGridViewTextBoxColumn();
col.HeaderText = "PRICE";
col.ValueType = typeof(int);
dataGridView1.Columns.Add(col);
col = new DataGridViewTextBoxColumn();
col.HeaderText = "QTY";
col.ValueType = typeof(int);
dataGridView1.Columns.Add(col);
}
}
}
Reply
Answers (
5
)
open office file in browser with out save
Help me code for print datagridview items in A4 size paper