Command Builders in 2.0

S

Steven Nagy

HI,

Has the SqlCommandBuilder changed at all? I have checked the
documentation and it seems exactly the same. But for the life of me,
I'm not getting the command builder to create the Insert,Update, and
Delete commands on my adapter.

Here's a simple example (I know you guys like quick illustrations of
the problem) that shows that its not working. This test fails on my
computer (security info is de-identified). (Note: You'll need NUnit GUI
to test this application):

using System;
using System.Data;
using System.Data.SqlClient;
using NUnit.Framework;

namespace TestExamples
{
[TestFixture()]
public class TestBadBuilders
{
public static SqlDataAdapter GetAdapter(string SQL, string
connection)
{
SqlDataAdapter da = new SqlDataAdapter(SQL, new
SqlConnection(connection));
SqlCommandBuilder builderSq = new SqlCommandBuilder(da);
//builderSq.RefreshSchema();
return da;
}

[Test()]
public void TestThatAdapterGetsAllCommands()
{
string sql = "SELECT * FROM [Build]";
string connection = @"Data Source=MyServer;" +
"Initial Catalog=MyCatalog;User
ID=MyUser;Password=xxxxxx";
SqlDataAdapter da = GetAdapter(sql, connection);

Assert.IsTrue(da.UpdateCommand != null);
}
}
}

This is actually an extracted snippet from a larger generic DAL. But
this code standalone does actually fail the Assert. Am I just missing
something stupid?

Thanks in advance,
Steven Nagy
 
C

chanmm

If you go and change the field and send da.UpdateCommand, does it update?
Check your database field and see anything is updated.

chanmm
 
S

Steven Nagy

No, it throws a null reference exception, as expected, because the
Insert command in the data adapter is null.

Need to identify why the builder is not creating Insert, Update, and
Delete commands for the data adapter.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top