•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C# section within the Software Development category of DaniWeb, a massive community of 429,998 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,505 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C# advertiser: Programming Forums
Views: 498 | Replies: 5 | Solved
![]() |
•
•
Join Date: Jun 2008
Location: Pasig City, Philippines
Posts: 10
Reputation:
Rep Power: 1
Solved Threads: 0
I have already connect my SQL database in C# windows application, Now, can somebody please give me sample codes for data manipulation, add/edit/delete of records....THANK you!
"LIFE is NOT A MATTER of CHANCE, it's a MATTER of CHOICE."
Layante, Dennis P.
Ripple E - Business International, Inc.
2202C-East Tower, Pasig City, Philippines 1605
Layante, Dennis P.
Ripple E - Business International, Inc.
2202C-East Tower, Pasig City, Philippines 1605
•
•
Join Date: Nov 2007
Location: � Jogja �
Posts: 2,585
Reputation:
Rep Power: 11
Solved Threads: 235
hmmm, how far u have done?show the code and other member can correct any mistaken..
Never tried = Never Know
So, Please do something before post your thread.
* PM Asking will be ignored *
So, Please do something before post your thread.
* PM Asking will be ignored *
•
•
Join Date: Jun 2008
Location: Pasig City, Philippines
Posts: 10
Reputation:
Rep Power: 1
Solved Threads: 0
Please help me...here's so far I have...I need codes for add/edit/delete records....
thanx...
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
string connectionString ="server=sroque\\sqlexpress;database=InventoryDB;uid=sa;pwd=ripple";
SqlConnection mySqlConnection = new SqlConnection(connectionString);
string selectString = "SELECT * FROM tblUsers";
SqlCommand mySqlCommand = mySqlConnection.CreateCommand();
mySqlCommand.CommandText = selectString;
SqlDataAdapter mySqlDataAdapter = new SqlDataAdapter();
mySqlDataAdapter.SelectCommand = mySqlCommand;
DataSet myDataSet = new DataSet();
mySqlConnection.Open();
string dataTableName = "tblUsers";
mySqlDataAdapter.Fill(myDataSet, dataTableName);
DataTable myDataTable = myDataSet.Tables[dataTableName];
foreach (DataRow myDataRow in myDataTable.Rows)
{
txtId.Text = "" + myDataRow["userID"];
txtUser.Text = "" + myDataRow["Name"];
txtPosition.Text = "" + myDataRow["Position"];
}
mySqlConnection.Close();
}
private void btnAdd_Click(object sender, EventArgs e)
{
if (btnAdd.Text == "&Add")
{
txtId.Text = "";
txtUser.Text = "";
txtPosition.Text = "";
btnAdd.Text = "&Save";
}
else if (btnAdd.Text == "&Save")
{
//then here I want to save records from the textbox to my database
}
}
}
}
thanx...
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
string connectionString ="server=sroque\\sqlexpress;database=InventoryDB;uid=sa;pwd=ripple";
SqlConnection mySqlConnection = new SqlConnection(connectionString);
string selectString = "SELECT * FROM tblUsers";
SqlCommand mySqlCommand = mySqlConnection.CreateCommand();
mySqlCommand.CommandText = selectString;
SqlDataAdapter mySqlDataAdapter = new SqlDataAdapter();
mySqlDataAdapter.SelectCommand = mySqlCommand;
DataSet myDataSet = new DataSet();
mySqlConnection.Open();
string dataTableName = "tblUsers";
mySqlDataAdapter.Fill(myDataSet, dataTableName);
DataTable myDataTable = myDataSet.Tables[dataTableName];
foreach (DataRow myDataRow in myDataTable.Rows)
{
txtId.Text = "" + myDataRow["userID"];
txtUser.Text = "" + myDataRow["Name"];
txtPosition.Text = "" + myDataRow["Position"];
}
mySqlConnection.Close();
}
private void btnAdd_Click(object sender, EventArgs e)
{
if (btnAdd.Text == "&Add")
{
txtId.Text = "";
txtUser.Text = "";
txtPosition.Text = "";
btnAdd.Text = "&Save";
}
else if (btnAdd.Text == "&Save")
{
//then here I want to save records from the textbox to my database
}
}
}
}
"LIFE is NOT A MATTER of CHANCE, it's a MATTER of CHOICE."
Layante, Dennis P.
Ripple E - Business International, Inc.
2202C-East Tower, Pasig City, Philippines 1605
Layante, Dennis P.
Ripple E - Business International, Inc.
2202C-East Tower, Pasig City, Philippines 1605
•
•
Join Date: Jun 2008
Location: Pasig City, Philippines
Posts: 10
Reputation:
Rep Power: 1
Solved Threads: 0
Please correct me if there's something wrong with my codes...It already have SQL Database connection and I successfully display my record from the database....
Please help me...here's so far I have...I need codes for data manipulation adding/edit/delete records....im using C#Windows Application
THANK YOU...you're a big help...
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
string connectionString ="server=sroque\\sqlexpress;database=InventoryDB;uid=sa;pwd=ripple";
SqlConnection mySqlConnection = new SqlConnection(connectionString);
string selectString = "SELECT * FROM tblUsers";
SqlCommand mySqlCommand = mySqlConnection.CreateCommand();
mySqlCommand.CommandText = selectString;
SqlDataAdapter mySqlDataAdapter = new SqlDataAdapter();
mySqlDataAdapter.SelectCommand = mySqlCommand;
DataSet myDataSet = new DataSet();
mySqlConnection.Open();
string dataTableName = "tblUsers";
mySqlDataAdapter.Fill(myDataSet, dataTableName);
DataTable myDataTable = myDataSet.Tables[dataTableName];
foreach (DataRow myDataRow in myDataTable.Rows)
{
txtId.Text = "" + myDataRow["userID"];
txtUser.Text = "" + myDataRow["Name"];
txtPosition.Text = "" + myDataRow["Position"];
}
mySqlConnection.Close();
}
private void btnAdd_Click(object sender, EventArgs e)
{
if (btnAdd.Text == "&Add")
{
txtId.Text = "";
txtUser.Text = "";
txtPosition.Text = "";
btnAdd.Text = "&Save";
}
else if (btnAdd.Text == "&Save")
{
//then here I want to save records from the textbox to my database
}
}
}
}
Please help me...here's so far I have...I need codes for data manipulation adding/edit/delete records....im using C#Windows Application
THANK YOU...you're a big help...
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
string connectionString ="server=sroque\\sqlexpress;database=InventoryDB;uid=sa;pwd=ripple";
SqlConnection mySqlConnection = new SqlConnection(connectionString);
string selectString = "SELECT * FROM tblUsers";
SqlCommand mySqlCommand = mySqlConnection.CreateCommand();
mySqlCommand.CommandText = selectString;
SqlDataAdapter mySqlDataAdapter = new SqlDataAdapter();
mySqlDataAdapter.SelectCommand = mySqlCommand;
DataSet myDataSet = new DataSet();
mySqlConnection.Open();
string dataTableName = "tblUsers";
mySqlDataAdapter.Fill(myDataSet, dataTableName);
DataTable myDataTable = myDataSet.Tables[dataTableName];
foreach (DataRow myDataRow in myDataTable.Rows)
{
txtId.Text = "" + myDataRow["userID"];
txtUser.Text = "" + myDataRow["Name"];
txtPosition.Text = "" + myDataRow["Position"];
}
mySqlConnection.Close();
}
private void btnAdd_Click(object sender, EventArgs e)
{
if (btnAdd.Text == "&Add")
{
txtId.Text = "";
txtUser.Text = "";
txtPosition.Text = "";
btnAdd.Text = "&Save";
}
else if (btnAdd.Text == "&Save")
{
//then here I want to save records from the textbox to my database
}
}
}
}
"LIFE is NOT A MATTER of CHANCE, it's a MATTER of CHOICE."
Layante, Dennis P.
Ripple E - Business International, Inc.
2202C-East Tower, Pasig City, Philippines 1605
Layante, Dennis P.
Ripple E - Business International, Inc.
2202C-East Tower, Pasig City, Philippines 1605
I can't debug your code or even read it, to make it easy, inform us with error raises when you run the code.
B.Sc Computer Science, Helwan University
Microsoft Student Partner
Personal blog http://ramymahrous.blogspot.com/
Arabic technical blog http://fci-h-ar.blogspot.com/
English technical blog http://fci-h.blogspot.com/
Microsoft Student Partner
Personal blog http://ramymahrous.blogspot.com/
Arabic technical blog http://fci-h-ar.blogspot.com/
English technical blog http://fci-h.blogspot.com/
![]() |
•
•
•
•
•
•
•
•
DaniWeb C# Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
amd avatar backup blue gene breach business chips daniweb data data protection database developer development dos energy enterprise europe government hardware hp ibm ibm. news intel ibm it linux management studio 2005 medicine memory microsoft news office open source openoffice pc ps3 recession red hat russia security server software sql sun supercomputer supercomputing trends ubuntu vista working x86
- conencting to SQL database via VB.net (VB.NET)
- how to connect SQL server 2000 to vb.net? (VB.NET)
- built in login and createuser wizard but for a remote SQL database? how to change? (ASP.NET)
- another MS SQL timeout problem (MS SQL)
- Validating a User Imput with SQL Database (Login) (C#)
- Problem Inserting into SQL database on server (ASP.NET)
- database problem (C#)
- Simple ASP.Net Login Page (Using VB.Net) (ASP.NET)
- Backing up a MySQL database (MySQL)
- Insert Dataset into SQL Database. (VB.NET)
Other Threads in the C# Forum
- Previous Thread: how to get primery key of table
- Next Thread: Parallel threading problem



Linear Mode