Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / June 2007

Tip: Looking for answers? Try searching our database.

Update when using sql server doesn't work

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
TonyJ - 29 Jun 2007 07:43 GMT
Hello!

I trying to update a table using sql server but no update will be done.

I don't get any error at all.

Here is an extract from the code. Does this seems to be right.

I have a Dataset and an Adapter

private void Form1_Load(object sender, EventArgs e)
{
  // TODO: This line of code loads data into the
'minDatabasDataSet1.Kunder' table. You can move, or remove it, as needed.
  this.kunderTableAdapter.Fill(this.minDatabasDataSet1.Kunder);
  this.kunderTableAdapter.
}

private void buttonUpdate_Click(object sender, EventArgs e)
{
   this.kunderTableAdapter.Update(this.minDatabasDataSet1.Kunder);
}

//Tony
Morten Wennevik [C# MVP] - 29 Jun 2007 16:53 GMT
Hi Tony,

There is nothing here that explains why your updates don't work.  Need more code for that.  What is the UpdateCommand string at the time of the update?

You could also try to adapt the code below, which should update the table (although that particular AdventureWorks table has some triggers updating the date field behind the scenes that may cause concurrency problems on the second update)

        SqlDataAdapter da = new SqlDataAdapter();
        DataSet ds = new DataSet();
        private void test1ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            using (SqlConnection conn = new SqlConnection("Data Source=(local);Initial Catalog=AdventureWorks;Integrated Security=SSPI;"))
            {
                using (SqlCommand com = new SqlCommand("SELECT * FROM Production.Culture", conn))
                {
                    using (da = new SqlDataAdapter(com))
                    {
                        da.Fill(ds);
                        dataGridView1.DataSource = ds;
                        dataGridView1.DataMember = "Table";
                    }
                }
            }
        }

        private void test2ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            using (SqlConnection conn = new SqlConnection("Data Source=(local);Initial Catalog=AdventureWorks;Integrated Security=SSPI;"))
            {
                using (SqlCommand com = new SqlCommand("SELECT * FROM Production.Culture", conn))
                {
                    using (da = new SqlDataAdapter(com))
                    {
                        using (SqlCommandBuilder b = new SqlCommandBuilder(da))
                        {
                            da.Update(ds);
                        }
                    }
                }
            }
        }

> Hello!
>
[quoted text clipped - 20 lines]
>
> //Tony

Signature

Happy coding!
Morten Wennevik [C# MVP]


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.