So this is my problem my fellow programmers: In my C# app, I have one button and a datagrid that is showing info from a sql table. Everytime I add a person into my datagrid, the data replicates instead of updating certain columns for that member. I need to somehow distinguish between inserting a new member, and updating an existing member inside my datagrid.
Below is two methods that are called once the UPDATE button is clicked. Does anyone know how to solve this irritating issue/ see a problem with my code??? Thanks in advance!
private void findMember()
{
sql = "SELECT Accounts.FirstName AS FirstName, Accounts.LastName AS LastName, Accounts.AccountID AS AccountID, AccountTypes.name AS Membership FROM Accounts JOIN AccountTypes ON AccountTypes.ID=Accounts.AccountType WHERE AccountID=" + newString;
da.SelectCommand = new SqlCommand(sql, cs);
cs.Open();
da.SelectCommand.ExecuteNonQuery();
cs.Close();
}
private void insertMember()
{
insertmembers = "INSERT INTO WaynokaLogger(FirstName, LastName, Membership, AccountID) SELECT Accounts.FirstName AS FirstName, Accounts.LastName AS LastName, AccountTypes.Name AS Membership, Accounts.AccountID AS AccountID FROM Accounts JOIN AccountTypes ON AccountTypes.ID=Accounts.AccountType WHERE AccountID=" + newString; // newString is variable that holds members AccountID #
da.InsertCommand = new SqlCommand(insertmembers, cs);
cs.Open();
da.InsertCommand.ExecuteNonQuery();
cs.Close();
}