1

I can't find how to do this on google anywhere. How do you save to a SQL DB using just C# code? Is it possible? The save method that comes default when you create a DB using the wizard dosen't actually save the DB:

this.Validate(); this.studentsBindingSource.EndEdit(); this.studentsTableAdapter.Update(this.studentsDataSet.FirstClass); 
7
  • Not exactly sure what you mean by "Save" the DB? Commented Apr 11, 2009 at 3:17
  • Actually update the file on the server not just the table adapter. Commented Apr 11, 2009 at 3:25
  • Are you able to retrieve data successfully from SqlServer? Commented Apr 11, 2009 at 3:28
  • Yep, it loads and when I click the save button it dosen't throw any exceptions or anything. I'm using SQL Server Express Edition and C# 2008 Express Edition. Does either of these matter? It's also stored on the localhost, as I don't have a server lying around :P Commented Apr 11, 2009 at 3:30
  • see additional question below Commented Apr 11, 2009 at 3:31

2 Answers 2

2

It looks to me as though you are doing it correctly.

You should check your table adapter and verify that there is an update statement assigned. If you're using sprocs and only have the select sproc assigned then it'll be read only (and won't prompt you for the update/insert/delete sprocs).

Sign up to request clarification or add additional context in comments.

13 Comments

I'm a newbie when it comes to SQL programming, what are sprocs?
SQL "stored procedures", but since you ask I presume that this is not reason.
If you do select your tableadapter and then expand the UpdateCommand property, there is a CommandText property, does that have a value?
I can't seem to find the UpdateCommand property in my tableadapter?
you've got your dataset open in design view?
|
1

Your connection string can be a few things depending on how you are configured to log into SQL.

Data Source=ServerName;Initial Catalog=DatabaseName;User Id=myUsername;Password=myPassword; 

or

Data Source=ServerName;Initial Catalog=DatabaseName;Integrated Security=SSPI; 

The latter is if you are using Windows Authentication; i.e. using the same user account you log into windows with.

DataSource is usually your machine's name or you can use (local) to get you over the hump should it be on the same machine you are working on.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.