|
I have a growing number of functions that look like some variation of the below, and it seems like there's got to be a way to generalize the whole process. Any suggestions?
Basically what I want is to load datatables from stored procedures.
Public Function UsersGetIconList(ByVal UserID As String, ByVal SPName As String, ByVal ParamArray args() As String) As DataTable
Dim DS As New DataSet("ResultSet")
Dim dt As DataTable = DS.Tables.Add("ResultTable")
Dim CON As New SqlConnection(strConnString)
Dim CMD As New SqlCommand(SPName, CON)
Dim reader As SqlDataReader
CMD.CommandType = CommandType.StoredProcedure
Try
'Use Parameters defined in Stored Procedure to pass on Variables.
Dim Param As SqlParameter = CMD.Parameters.Add("@UserID", SqlDbType.VarChar, 36)
Param.Value = UserID
Param = CMD.Parameters.Add("@User_Icon_FileLocation", SqlDbType.NChar, 256)
CMD.Parameters("@User_Icon_FileLocation").Direction = ParameterDirection.Output
'Open Database and Execute Query as defined in Stored Procedure.
CON.Open()
reader = CMD.ExecuteReader()
dt.Load(reader)
Catch ex As Exception
'MsgBox(ex.Message)
Finally
CON.Close()
End Try
'Data is accessible through the DataReader object here.
Return dt
End Function
|
|
|
|
|
You need a generic method that gives you a DataTable after executing a stored-procedure? If yes, how about a function signature like
Public Function GetDataTable(ByVal SPName As String, ByVal ParamArray parameters() As SqlParameter) As DataTable
You need to create and pass SqlParameter instances. Inside this function, add all parameters to the command and fill a datatable. Using strongly typed data structures is the preferred method. If you want to use DataTable , use typed DataTable and enjoy the advantages of type safety.
I'd personally avoid DataTable or DataSet. If I have to use, I prefer typed ones. Usually data access methods should return typed POCO (plain old CLR object) or DTO (data transfer object) objects. You will have a common method that will do data access and return a SqlDataReader or IDataReader if you care about extending to other databases.
Your UsersGetIconList() method can utilize the common method and get a data reader. Using this reader, create your own DTO object and return.
|
|
|
|
|
Thanks N a v a n e e t h.
Of course now I'm thoroughly confused.
I'm a bit beyond my comfort zone here. I know how to deal with datatables, and it seems like Stored Procedures are something that I definately need to learn about. I just bought a SQL Server Dev book, so hopefully that'll help.
It seems to me like getting data into the Stored Procedure is easier than getting it back out, and I think I'm thinking about something dreadfully wrong about the process...
|
|
|
|
|
Member 4125480 wrote: It seems to me like getting data into the Stored Procedure is easier than getting it back out, and I think I'm thinking about something dreadfully wrong about the process...
You push data into a stored proc as parameters, then you call it, and the data comes out. The data coming out is really no different to if you just ran SQL that you mashed together.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
Hi!
I have a GridView on an aspx page that displays records. Below the GridView I have a TextBox that needs to display the value I select in the GridView
I have already created a linkbutton that enables me to click on the record number but I cannot get the value into the textbox.
How can I do this?
Illegal Operation
|
|
|
|
|
I assume that you have the value on the querystring, hence the title of your question ? Read it from there and put it in your textbox.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
ok I get the ID from the querystring but I need to get the firstname and lastname for that record and put them in textboxes as well.
I understand how to get the ID from the querystring but How can I iterate through the record and populate the values?
Illegal Operation
|
|
|
|
|
Oh - so you need to look up a record in the database to get the value ? Or you need to step over your data source to find it ?
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
yes. I have a record with ID, FirstName, LastName and Date and would like to populate a form when I click on the record ID.
Illegal Operation
|
|
|
|
|
ok, so, again, if it's a new form you populate, put the ID on the URL, and read the other data from the database. Simple.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
All you need to do is just setting text box value, why not do it using JS? Hook a JS function which will execute when link button is clicked and get necessary values and assign to textbox.
|
|
|
|
|
Hi,
find the respective control in gridview using findcontrol method and then get the value of that control,
cheers,
praveen.
|
|
|
|
|
Hi to all
i am new face to asp.net
i develop a website in asp.net (language = vb) in .NET 2.0. In my system i run the project. i want to upload the site in a web server. i have web server and domain name. can any tell pls how to upload my site in web server
i have change a file content to run in web pls tell me step by step procedure to upload my site
|
|
|
|
|
You need to talk to your web host to find out how to upload the site to them. Does your site use a database ? You'll have to move that too, and reset the connection string.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
there is no need for database in my website. i just publish the site and save that in a folder after that move all the files in web server may i know this is correct way to upload the site in web server
|
|
|
|
|
You just copy the working site from your development directory onto the server. You don't need to publish anything.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
it need any web.config file and bin dir
|
|
|
|
|
Yes, of course it does, that's why those things exist. Copy the entire folder.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
i need to change any code in web.config when i am uploading right now i am uploading the site
|
|
|
|
|
Why don't you try doing what I say, and report back if you have any issues ? If you don't have any connection strings in there, or other paths that would change, then you shouldn't need to change it, no.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
i upload my its show's error like this
Runtime Error
Description: An application error occurred on the server. The current custom error settings for this application prevent the details of the application error from being viewed remotely (for security reasons). It could, however, be viewed by browsers running on the local server machine.
Details: To enable the details of this specific error message to be viewable on remote machines, please create a <customErrors> tag within a "web.config" configuration file located in the root directory of the current web application. This <customErrors> tag should then have its "mode" attribute set to "Off".
<!-- Web.Config Configuration File -->
<configuration>
<system.web>
<customErrors mode="Off"/>
</system.web>
</configuration>
Notes: The current error page you are seeing can be replaced by a custom error page by modifying the "defaultRedirect" attribute of the application's <customErrors> configuration tag to point to a custom error page URL.
<!-- Web.Config Configuration File -->
<configuration>
<system.web>
<customErrors mode="RemoteOnly" defaultRedirect="mycustompage.htm"/>
</system.web>
</configuration>
|
|
|
|
|
after i change the RemoteOnly to off it shows the same error
|
|
|
|
|
You will need to work out how to get it to show you the actual error in order to fix it. Can you log into the server and view it there ? If not, check the settings, but I suspect it's cached the web.config and needs to be reset in order to show you the real error.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
i cont understand, can pls tell me clearly
|
|
|
|
|
If you changed the web.config on the server, it's possible the server is still reading the old version because of some sort of cache. Beyond that, you need to work out why it's not showing you the actual error, or you can't do anything to fix it. If you could either log in to the server, or go to it physically, the right error would show if you browsed to the site from the server.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|