|
public DataSet GetEntries()
{
string sql = "SELECT TOP 5 * FROM [HJ_BLog] ORDER BY Date DESC";
string ConnectionString = ConfigurationSettings.AppSettings.Get("connString");
SqlConnection conn;
DataSet ds;
SqlCommand cmd;
SqlDataAdapter da;
try
{
conn = new SqlConnection(ConnectionString);
cmd = new SqlCommand(sql, conn);
da = new SqlDataAdapter(cmd);
ds = new DataSet();
da.Fill(ds);
}
catch (Exception ex)
{
}
finally
{
if (da != null) da.Dispose();
if (cmd != null) cmd.Dispose();
if (conn != null) conn.Dispose();
}
return ds;
}
|
|
|
|
|
Thank you, I have no idea what i was thinking when i wrote this.
|
|
|
|
|
Hi Jacob,
I have a couple of fairly phylisophical points to add. Ignore them as you please .
First off, it's not a really good idea to change database schema from within your code. Creating and deleting view (and table and sprocs, etc) are really design-time processes. Do it before-hand and be done. Why? Well, what happens when user #2 tries to create the view before user #1 drops? You've got an exception to handle... It just get's too messy.
Related to the first point, I am very leary of a program running with a sql user that has sufficient privileges to alter the db schema.
Just my $0.02
Bill
|
|
|
|
|
Is it possible to position to a specific row in a DataTable or DataView? I have a DataGrid that displays either a detail view or a summary view and uses built-in paging. Both sets of data are from the same database table, the summary view is an aggregate (group by) with one less column than the detail view.
When the user changes views, I execute the appropriate stored procedure and re-bind the results to the grid. The problem is I need to re-display the same page of records in the new view. In other words, if the record for company ABC was the first record displayed in the grid in one view, it needs to be the first record in the other view as well. Currently if the user has paged down to page 3 and changes views, they are back on page 1.
Thanks for you help,
Mark
|
|
|
|
|
Hi Mark,
Is this a paging problem or a sql problem? I mean: do the two sprocs return the same rows in the same order? If so, can't you just grab the current page# from the datagrid (CurrentPageIndex) and then set it again before you bind to the new data?
Bill
ps: code snippets would help...asp.net datagrid ?
|
|
|
|
|
I am writing a small inventory application at home using VS2005. I have installed the latest build of MSDE on my machine, created a table, and defined the fields within it.
One of the field definitions lets me create an image field in the table.
What I'd like to know is how to save and retrieve an image (bmp) into that part of the table. Do I pass image as a string? How do I retrieve it and load it into the PictureBox? Do I just do a Convert on it?
I noticed that the SqlReader provides a means of retrieving all of the database types, except GetImage() !!
Any help would be appreciated.
This signature left intentionally blank
|
|
|
|
|
Use GetBytes to retrieve images from SQL. Once you have the bytes, it should be easy enough to get that into a picturebox.
my blog
|
|
|
|
|
Are you looking to hire a programmer to build for you a library management project? Or would you just like someone to give you such a project for free? Sounds like a big job.
On the other hand, if you were building it yourself and had a specific question, this would be a good place to ask it.
|
|
|
|
|
|
Nope, guess not.
It does seem like there are more and more of these questions - the kind where the poster just asks for a major system, and how soon can we get it to him/her. I see he/she deleted the original post. I try to be as polite as I can be with these sorts of things, and encourage these sorts of posters to ask the more specific questions that can be effectively addressed in a forum like this. But I'm starting to realize why others on the forums give up on the polite approach and just start hammering these guys.
Oh well.
|
|
|
|
|
HI there,
I have a dataset that I'm returning from a query, the problem i'm having is how can I bind the data to a table control? I only need to render three of the columns, but I guess the configuration I need to pretty complex.
for each colour desc there is multiple quantitys * sizes, if someone could help me out with the code I would really appreciate it as I have tried nested datalists & datagrids.
colourdesc | sizedesc | sizedesc | sizedesc |
----------
value qoh | qoh | qoh |
----------
value
------------
sample data
+------------+------+------+-----------+--------+---------------+----------+
| qoh | size | shop | style | colour | colourdesc | sizedesc |
+------------+------+------+-----------+--------+---------------+----------+
| 0000000000 | 3 | 1 | 10475RIB1 | 2 | BLACK | XS |
| 0000000002 | 4 | 1 | 10475RIB1 | 2 | BLACK | S |
| 0000000000 | 5 | 1 | 10475RIB1 | 2 | BLACK | M |
+------------+------+------+-----------+--------+---------------+----------+
Sean - thanks in advance
|
|
|
|
|
I have an application (C#/ADO.NET) that collects alarms from equipment at around 100 sites, through concurrent TCP/IP listeners. Per day I receive about 1 million messages (~10/sec). I used to insert them directly into the destination table, but that would lock up the table so user access (read/reporting) was hardly possible. Now I insert the data in a intermediate table and upload it every 5 min. to the final table with SQl agent.
First of all, this doesn't look like an elegant solution. Furthermore, performance is still quite bad. Even though I have just this one DB/table, SQL-server uses up all available memory (1.5Gb out of 2Gb) and all available CPU, 24x7; I'm just wainting for a melt-down...
Anybody have any experience with this amount of transactions, and/or any suggestions?
Thanks.
|
|
|
|
|
Do you have the relevant clustered index on your table? Your table should have a clustered index so that new items are added to the end of the index and the index does not then need to be reordered.
Affordable and reliable hosting? Click here!
|
|
|
|
|
Does Sybase SQL Anywhere 8 support row lock?
I'm writing a MFC application that already implemet row lock with Oracle via ODBC.
In Oracle I use:
1. Start a transaction
2. Lock a record (SELECT * FROM Table WHERE ID = 1 FOR UPDATE NOWAIT)
3. Wait for a user record's modify
4. Commit
If another user tries to modify the record, Oracle returns an error message.
Is it possible to implement this with Sybase' server ?
Thank you
Vin.
vin
|
|
|
|
|
I'm trying to execute an SQL statement with parameters through a Command object. I've done it a thousand times through ADO.NETs SqlCommand object, but now i'm using ADOs Command object from vb6. Is it possible, cos its not working.
lEntry_ID = 5
Dim cmd As Command
Set cmd = New Command
Set cmd.ActiveConnection = gConn
cmd.CommandType = adCmdText
cmd.Parameters.Append cmd.CreateParameter("@Entry_ID", adInteger, adParamInput, , lEntry_ID)
cmd.CommandText = "SELECT * FROM Entry WHERE ID = @Entry_ID"
If cmd.Execute.EOF then
'blah
End If
I get the error "Must supply a value for variable: @Entry_ID". Any help would be appreciated.
--
Dave
|
|
|
|
|
With VB6/ADO you do not use named parameters in the CommandText... you use positional parameters:
cmd.Parameters.Append cmd.CreateParameter("Entry_ID", adInteger, adParamInput, , lEntry_ID)<br />
cmd.CommandText = "SELECT * FROM Entry WHERE ID = ?"
More or less the same was as with the ADO.NET ODBC provider.
Regards,
Rob
--
RMTrack a new bug tracking tool. Available now from http://www.rmtrack.com
|
|
|
|
|
rmacfadyen wrote:
With VB6/ADO you do not use named parameters in the CommandText... you use positional parameters
Thats what I was afraid of. The parameters could appear in any order in the SQL (or might not be there at all). Oh well, i'll just have to do it myself with Replace
Thanks
--
Dave
|
|
|
|
|
Umm... doing it with replace is may be a bad idea unless you're careful about escaping and formatting your parameters correctly (sql injection attacks can't happen if you use parameterized queries).
Are you sure the parameters could appear in any order?
Regards,
Rob
--
RMTrack a new bug tracking tool. Available now from http://www.rmtrack.com
|
|
|
|
|
Hi there..
How do I code the syntax :
myTable.Columns["mycolumnName"].myProperty = "value";
I have
a table class 'myTable' that inherits from System.Data.DataTable.
a column class 'myColumn' inherits from System.Data.Datacolumn.
As it is now I don't have acces to 'myProperty' that is a member of 'myColumn'.
-To get access I first have to convert it to 'myColumn' see below ???
((myColumn) myTable.Columns["mycolumnName"]).myProperty = "value";
thx..
|
|
|
|
|
What you're doing looks correct to me. If myTable.Columns["..."] returns a DataColumn type, then you would have to cast it to a myColumn type to use a myColumn property.
I suppose you could define a property like Columns in your custom table class that returns objects of type myColumn rather than DataColumn . Otherwise, just casting is fine.
|
|
|
|
|
Sure, but myTable.Columns returns a collection of DataColumn..
I want the Columns property to return a collection of myColumn
-I have to somehow override the Columns property in my 'myTable' that inherits the Columns property from the baseclass DataTable..
|
|
|
|
|
I think if it were me I would just define a function or property called MyColumns that could return a myColumn object that has been cast by the function from the corresponding DataColumn .
If you're coding in VB, I suppose you could use the Shadows keyword to created your own shadowed property called Columns , but I don't think this would be the way I'd go (and shadows isn't available in C# anyway).
|
|
|
|
|
Yes, but still my issue is not resolved.. I don't have problem getting a single column of type 'myColumn'..
The problem is 'Columns' property still return a collection of type System.Data.DataColumn
|
|
|
|
|
I have a problem with triggers and transactions I need to create a trigger after insert on a table but I would like to fire that trigger only after committing the transaction not before the and on the transaction, any body can help me with this problem I will be thankful for that
regards
Mhmoud Rawas
------------
Software Eng.
|
|
|
|
|
Mhmoud,
As far as I know triggers cannot be made to work this way. They fire. Period.
I would take you logic in the trigger and make a stored procedure out of it. Then call the new stored procedure after you commit the original transaction. You will not have access to Inserted and Deleted but this is the only way I know to do what you describe
Hope this helps
Bill
|
|
|
|