16,009,847 members
Sign in
Sign in
Email
Password
Forgot your password?
Sign in with
home
articles
Browse Topics
>
Latest Articles
Top Articles
Posting/Update Guidelines
Article Help Forum
Submit an article or tip
Import GitHub Project
Import your Blog
quick answers
Q&A
Ask a Question
View Unanswered Questions
View All Questions
View C# questions
View C++ questions
View Javascript questions
View Visual Basic questions
View .NET questions
discussions
forums
CodeProject.AI Server
All Message Boards...
Application Lifecycle
>
Running a Business
Sales / Marketing
Collaboration / Beta Testing
Work Issues
Design and Architecture
Artificial Intelligence
ASP.NET
JavaScript
Internet of Things
C / C++ / MFC
>
ATL / WTL / STL
Managed C++/CLI
C#
Free Tools
Objective-C and Swift
Database
Hardware & Devices
>
System Admin
Hosting and Servers
Java
Linux Programming
Python
.NET (Core and Framework)
Android
iOS
Mobile
WPF
Visual Basic
Web Development
Site Bugs / Suggestions
Spam and Abuse Watch
features
features
Competitions
News
The Insider Newsletter
The Daily Build Newsletter
Newsletter archive
Surveys
CodeProject Stuff
community
lounge
Who's Who
Most Valuable Professionals
The Lounge
The CodeProject Blog
Where I Am: Member Photos
The Insider News
The Weird & The Wonderful
help
?
What is 'CodeProject'?
General FAQ
Ask a Question
Bugs and Suggestions
Article Help Forum
About Us
Search within:
Articles
Quick Answers
Messages
Comments by Member 12718897 (Top 6 by date)
Member 12718897
13-Sep-16 23:02pm
View
private void btnsave_Click(object sender, EventArgs e)
{
SqlConnection connection = new SqlConnection(cn);
foreach (DataGridViewRow row in dgprdesc.Rows)
{
using (SqlCommand cmd1 = new SqlCommand("INSERT INTO ProductSell VALUES(@ProjectID, @ProductName, @SupplierName,@ProductCost,@ProductPrice,@ProductQuantity)", connection))
{
cmd1.Parameters.AddWithValue("@ProjectID", row.Cells["Project ID"].Value);
cmd1.Parameters.AddWithValue("@ProductName", row.Cells["Product Name"].Value);
cmd1.Parameters.AddWithValue("@SupplierName", row.Cells["Supplier Name"].Value);
cmd1.Parameters.AddWithValue("@ProductCost", row.Cells["Product Cost"].Value);
cmd1.Parameters.AddWithValue("@ProductPrice", row.Cells["Product Price"].Value);
cmd1.Parameters.AddWithValue("@ProductQuantity", row.Cells["Product Quantity"].Value);
connection.Open();
cmd1.ExecuteNonQuery();
connection.Close();
}
}
string date = pdate.Value.ToString("yyyyMMdd");
SqlCommand cmd = new SqlCommand("insert into Project (ProjectID,ProjectName,ClientName,Date)values('" + txtprid.Text + "','" + txtprname.Text + "','" + cmbclient.Text + "','" + date + "')", connection);
connection.Open();
cmd.ExecuteNonQuery();
connection.Close();
MessageBox.Show("Reocrd Added Successfully");
btnew.Enabled = true;
btnsave.Enabled = false;
txtprname.Enabled = false;
pdate.Enabled = false;
cmbclient.Enabled = false;
cmbproduct.Enabled = false;
cmbsupplier.Enabled = false;
txtcost.Enabled = false;
txtprice.Enabled = false;
txtquantity.Enabled = false;
}
Member 12718897
13-Sep-16 22:14pm
View
after saving data using save button,if i want to add more rows in same project so i am using edit button on my form . after that i select particular project from combo box and it will load all data from databse in datagrid view ,in same grid view i want to add some more rows after the old data and it should be save in database
Member 12718897
13-Sep-16 21:49pm
View
yes it is working fine when i start new project that time functioning very well, but when i am trying to edit project that time it is not working.
Member 12718897
13-Sep-16 21:00pm
View
public partial class NewProject : Form
{
string cn = ConfigurationManager.ConnectionStrings["con"].ConnectionString;
DataTable dt = new DataTable();
public NewProject()
{
InitializeComponent();
}
private void NewProject_Load(object sender, EventArgs e)
{
SqlConnection connection = new SqlConnection(cn);
//TO LOAD CLIENT LIST
SqlCommand cmd = new SqlCommand("select * from Client",connection);
connection.Open();
SqlDataReader sdr = cmd.ExecuteReader();
while (sdr.Read())
{
cmbclient.Items.Add(sdr["ClientName"].ToString());
}
sdr.Close();
connection.Close();
//TO LOAD SUPPLIER LIST
SqlCommand cmd1 = new SqlCommand("Select * from Supplier", connection);
connection.Open();
SqlDataReader sdr1 = cmd1.ExecuteReader();
while (sdr1.Read())
{
cmbsupplier.Items.Add(sdr1["SupplierName"].ToString());
}
sdr1.Close();
connection.Close();
//TO LOAD PRODUCTS
SqlCommand cmd2 = new SqlCommand("Select * from Product", connection);
connection.Open();
SqlDataReader sdr2 = cmd2.ExecuteReader();
while (sdr2.Read())
{
cmbproduct.Items.Add(sdr2["ProductName"].ToString());
}
sdr2.Close();
connection.Close();
//TO ADD DATA INTO GRID VIEW
dt.Columns.Add("Project ID",typeof(string));
dt.Columns.Add("Product Name",typeof(string));
dt.Columns.Add("Supplier Name", typeof(string));
dt.Columns.Add("Product Cost", typeof(float));
dt.Columns.Add("product Price", typeof(float));
dt.Columns.Add("Product Quantity", typeof(int));
dgprdesc.DataSource = dt;
}
private void label1_Click(object sender, EventArgs e)
{
}
private void btnclose_Click(object sender, EventArgs e)
{
this.Close();
}
private void btnadd_Click(object sender, EventArgs e)
{
dt.Rows.Add(txtprid.Text,cmbproduct.SelectedItem,cmbsupplier.SelectedItem,txtcost.Text,txtprice.Text,txtquantity.Text);
dgprdesc.DataSource = dt;
}
private void btnremove_Click(object sender, EventArgs e)
{
foreach (DataGridViewRow item in this.dgprdesc.SelectedRows)
{
dgprdesc.Rows.RemoveAt(item.Index);
}
}
private void btnew_Click(object sender, EventArgs e)
{
btnew.Enabled = false;
btnsave.Enabled = true;
txtprname.Enabled = true;
pdate.Enabled = true;
cmbclient.Enabled = true;
cmbproduct.Enabled = true;
cmbsupplier.Enabled = true;
txtcost.Enabled = true;
txtprice.Enabled = true;
txtquantity.Enabled = true;
}
private void btnsave_Click(object sender, EventArgs e)
{
SqlConnection connection = new SqlConnection(cn);
foreach (DataGridViewRow row in dgprdesc.Rows)
{
using (SqlCommand cmd1 = new SqlCommand("INSERT INTO ProductSell VALUES(@ProjectID, @ProductName, @SupplierName,@ProductCost,@ProductPrice,@ProductQuantity)", connection))
{
cmd1.Parameters.AddWithValue("@ProjectID", row.Cells["Project ID"].Value);
cmd1.Parameters.AddWithValue("@ProductName", row.Cells["Product Name"].Value);
cmd1.Parameters.AddWithValue("@SupplierName", row.Cells["Supplier Name"].Value);
cmd1.Parameters.AddWit
Member 12718897
6-Sep-16 5:20am
View
I tried something like that
for saving new record on one button named as save
private void btnsave_Click(object sender, EventArgs e)
{
SqlConnection connection = new SqlConnection(cn);
SqlCommand cmd = new SqlCommand("insert into myname (name)values('"+txtpname.Text+"')", connection);
connection.Open();
cmd.ExecuteNonQuery();
connection.Close();
MessageBox.Show("Reocrd Added Successfully");
//SqlConnection connection = new SqlConnection(cn);
SqlCommand cmd1 = new SqlCommand("select * from myname", connection);
SqlDataAdapter sdr = new SqlDataAdapter(cmd1);
SqlCommandBuilder scb = new SqlCommandBuilder(sdr);
DataSet ds = new DataSet();
connection.Open();
sdr.Fill(ds);
connection.Close();
dgproduct.DataSource = ds.Tables[0];
}
And for edit than save using 2 button named as editsave
private void btneditsave_Click(object sender, EventArgs e)
{
SqlConnection connection = new SqlConnection(cn);
SqlCommand cmd = new SqlCommand("update myname set Name='"+txtpname.Text+"' where ID ='" + txtpid.Text + "'", connection);
connection.Open();
cmd.ExecuteNonQuery();
connection.Close();
MessageBox.Show("Reocrd Upadted Successfully");
//SqlConnection connection = new SqlConnection(cn);
SqlCommand cmd1 = new SqlCommand("select * from myname", connection);
SqlDataAdapter sdr = new SqlDataAdapter(cmd1);
SqlCommandBuilder scb = new SqlCommandBuilder(sdr);
DataSet ds = new DataSet();
connection.Open();
sdr.Fill(ds);
connection.Close();
dgproduct.DataSource = ds.Tables[0];
txtpname.Enabled = false;
}
but I want only one save button on my form which can be use as to save new record
and as well as after editing record to update.
Member 12718897
3-Sep-16 21:40pm
View
Deleted
sorry but I am new to this
I wrote something like this
add name="con" connectionstring="Data Source=.;Initial Catalog=AAA.mdf;Integrated Securiry=True"
can you please give more description for what will go in this syntax
Show More