Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Development Tools
 ASP.NET
 Using Data Access App Block

Author  Topic 

Hommer
Aged Yak Warrior

808 Posts

Posted - 2006-05-05 : 09:31:45
Hi, All!

I just started my first full data access app in dotnet on my own. I thought a good way is to use MS Data Access Application Block (DAAB).

I got this build error.

Type 'ExecuteDataset' is not defined.

I have my winform gui .vb code in one project calling Microsoft.ApplicationBlocks.data project.

ExecuteDataset in SQLHelper.cs is defined as Public Static. What else do I need to do to make my gui knows the function? I tried to use Imports, set a reference to it, and/or referencing it as the documentation has suggested, but don't know why it is not working.

Thanks!

Hommer
Aged Yak Warrior

808 Posts

Posted - 2006-05-05 : 09:57:19
Ok, I got it.
has to be
Dim ds As DataSet = SqlHelper.ExecuteDataset()
instead of
Dim ds As DataSet = New ExecuteDataset()
Go to Top of Page

Hommer
Aged Yak Warrior

808 Posts

Posted - 2006-05-05 : 15:12:14
I am running into another error continuing down to the same path as my previous post. Now I got an unhandled system error on system.data.dll.

The code broke on da.fill(ds); line as listed below. I have tested the connection string and the stored proc, and they are all working.

This function is from MS DAAB. The documentation and sample code did not give any clue.

What else should I do? Thanks!

public static DataSet ExecuteDataset(SqlConnection connection, CommandType commandType, string commandText, params SqlParameter[] commandParameters)

{

//create a command and prepare it for execution

SqlCommand cmd = new SqlCommand();

PrepareCommand(cmd, connection, (SqlTransaction)null, commandType, commandText, commandParameters);

//create the DataAdapter & DataSet

SqlDataAdapter da = new SqlDataAdapter(cmd);

DataSet ds = new DataSet();

//fill the DataSet using default values for DataTable names, etc.

da.Fill(ds);

// detach the SqlParameters from the command object, so they can be used again.

cmd.Parameters.Clear();

//return the dataset

return ds;

}

Go to Top of Page

Hommer
Aged Yak Warrior

808 Posts

Posted - 2006-05-08 : 09:34:30
And, here is my calling code. Couple things. First the ExecuteScalar went through and got the data. That indicated the connString is OK.

It chocked on SqlHelper.ExecuteDataset line. If I did not add try/catch, it chocked on da.Fill(ds); as my earlier post showed.

Both case, it said unhandled error. When I stepped through it, I could see that my parameter is set, i.e. data type, direction and value are all correct.

Thanks!

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click

Dim connString As String = "Data Source=Sss;Initial Catalog=Qqq;Integrated Security=SSPI;"

Dim mytime As String

mytime = CType(SqlHelper.ExecuteScalar(connString, CommandType.StoredProcedure, "GetMyDate"), String)

TextBox1.Text = mytime



Dim arParms() As SqlParameter = New SqlParameter(0) {}

arParms(0) = New SqlParameter("@P", SqlDbType.Int)

arParms(0).Value = 53018

Try

Dim ds As DataSet = SqlHelper.ExecuteDataset(connString, CommandType.StoredProcedure, "OP_getCLG3", arParms)

TextBox1.Text = ds.ToString

MsgBox("here is the get date result:" + ds.ToString())

Catch ex As Exception

' throw an exception

Throw ex

End Try

End Sub
Go to Top of Page

Hommer
Aged Yak Warrior

808 Posts

Posted - 2006-05-08 : 10:15:41
Ok, I got it.

The parameter name in the calling part has to be the same as declared in the sp. I did not know that is a requirement!
Go to Top of Page
   

- Advertisement -