Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Database question C# w/VS2005

Status
Not open for further replies.

gplusplus

Programmer
Jan 17, 2007
30
0
0
US
I wanted to created a simple windows application for learning purpose. The objective was to simply have A database containing one Table, named "Table". The table would have a primary key called "id" and would be automatically incremented. Then the other field would be "name" of varchar type. I created the SQL database with visual studio 2005 as well as the rest of the project.

Then i would have simple form that has one listbox that would contain all the current listings in the database and then under that a textbox where u could add a name to the database, by filling in the textbox and clicking and add button that triggers an event to store it to the dataset then acutally updating the db.

So right now the listbox is populating correctly. And if you type a name into the box to add, it adds to the dataset correctly and populates in the listbox. The when i run the update method to actually store it in the db, i get a messagebox that says 1 row has been affected. (i put the message box in there for debugging purpose). So then i close the application and then hit F5 again to debug it again, and what names i added on the previous run did not store in the db.

If i go to the bin folder and run the actual exectuable, everything works perfect, i can add a name to the db, close the exe and re-run it and its there..... So i dont know if there is some kind of setting i would have to change to get the db to store while im in Visual Studio debugging. I have an example i found on the web that works either way, so i know its possible....Im just wondering if im missing a step. Heres my main form code:

Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WindowsApplication3
{
public partial class Form1 : Form
{

public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
this.tableTableAdapter.Fill(this.testDataSet.Table);

}

private void addButton_Click(object sender, EventArgs e)
{
testDataSet.TableRow n = testDataSet.Table.NewTableRow();
n.name = nameTextBox.Text;
testDataSet.Table.AddTableRow(n);
MessageBox.Show("Added Row Value: " + n.name);
int rE = tableTableAdapter.Update(n);
MessageBox.Show("Rows Affected: " + rE.ToString());
}
}
}

Please let me know if you need anymore information

thanks

Abe
 
Can you please be more specific and brief with your question?
 
I created a database in VS2005 and then made a simple form. The form allows you to add to the database. When I click the add button it appears to add to the dataset correctly. It also appears to have stored it on the database. After i quit running the app in debug mode and then rerun it, the entries i added in on my previous ones were not stored. If i just run the exe out of the bin file everything works perfect.

I want to run in debug mode and be able to save stuff to the database successfully. I have an example offline that works either way debug mode or running the exe out of bin. Is there a setting i need to change.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top