|
I have the following table field name = "ordDate" which holds DateTime for orders. Ive tried the query below but without success. I need to get all information based on the passed "DateTime". any help will be apreciated
select *
from order
WHERE ord_date = CONVERT .ToDateTime('14/09/1994')
|
|
|
|
|
<br />
select *<br />
from order<br />
WHERE ord_date = @ComparedDate<br />
@ComparedDate is a DateTime parameter, you have to provide it's value from caller.
<br />
Dim cmd as new SqlCommand(select * from order WHERE ord_date = @ComparedDate", conn)<br />
cmd.Parameters.Add(new SqlParameter("@ComparedDate", SqlDataType.DateTime)).Value=Convert.ToDateTime("14/09/1994")<br />
Dim reader as SqlDataReader=cmd.ExecuteReader()<br />
...<br />
|
|
|
|
|
How do I Commit changes that I edit in a DataGridView that I have used databinding from my SQL Server?
_____________________________
...and justice for all
APe
|
|
|
|
|
Hi,
Is there a way to restore a database with using .bak file? Either from "data file" or "log file"? I got a copy of those from the Microsoft website but how to restore this?
Many thanks.
|
|
|
|
|
Create a new database of the same name.
Then restore the bak file over the newly created database. The thing you need to watch for is that the bak file stores the file location of the log and data when it was backed up. You will need to change this to the actual file locations on your computer.
|
|
|
|
|
Hi,
I executed a stored procedure through VS2005 and the true boolean coloumsn came backs -1, and false as 0. Why didn't it display 1 for the true coloumns?
Regards,
ma se
|
|
|
|
|
In this case, the database stored boolean as a signed type (integer for example). All bits will be 1 for true and 0 for false. If first bit is 1, then that value is a negative one.
|
|
|
|
|
It has been a very frustrating effort attempting to find the root cause of this problem. I have searched the web sites and there is no definitive explanation. Likewise, this same message has been posted on Microsoft's SQL Server forum. There have been many viewers, but no responders.
We are running a Visual Studio C++ application using Sql Server / ODBC. SQL Queries are formatted and exceuted from the C++ code.
This particular SQL Error occurs about once every few months. Since the time of the last error, I added additional debug statements which log the exact format of the SQL Query that is being executed.
This is the SQL query that just failed.
SELECT * FROM [LaneInventory] WHERE (LaneInventory.LocationName = 'LANE_06');
The query that failed is executed hundreds of times within a 24 hour period every day, with the only exception being the location name changes in the query. The same exact query identified above was executed successfully about 15 minutes prior to this failure.
The SQL Exception message is very misleading.
I am wondering if SQL Server gets into a confused state every one in a while, or maybe it is a problem with the ODBC driver. The C++ application code is running on Windows 2003.
AbbyDabby
|
|
|
|
|
I'm not expert on databases, but the error is "Attempt to open a table failed"...so is it possible that your problem is caused by two people accessing the same file at the same time...one of them failing to open it because the other one had it locked? Or is there some other scenario where that file could be locked or unavailable for any reason?
|
|
|
|
|
Hi,
I currently have a DataGrid which retrieves the Surname of a user into one of the columns using an SQL View.
I would like to have the SQL View retrieve both Surname AND Forename.
Here's the current view:
SELECT tblProject.inProjectID, tblProject.vchProjectName, tblUser.vchSurname, tblProject.dtStartDate, tblProject.dtCompletionDate
FROM tblProject INNER JOIN
tblUser ON tblProject.inProjectManagerID = tblUser.inUserID
The view allows the display of the Surname. I would like to display "Surname, Forename" i.e. "Smith, John"
I used the following query for application on a DropDownList:
"SELECT tblUser.inUserID, tblUser.vchSurname + ', ' + tblUser.vchForename AS ForenameANDSurname FROM tblUser ORDER BY tblUser.vchSurname"
I just can't seem to fit it into the View
Any Ideas?
Thanks
|
|
|
|
|
Dayekh wrote: I used the following query for application on a DropDownList:
How do u fil DropDownList???
Do u set DataSource,DataValueField,DataTextField???
|
|
|
|
|
Yes indeed, I set all three of them.
Remember, the data text field will be the new alias that you specified for the fields.. ie forename field + surname field = "Fullname"
|
|
|
|
|
ur alias column (alias columns is forename field + ', ' + surname field as fullname) have to be DataTextField of dropdownlist
i.e
forename field + ', ' + surname field as fullname<br />
<br />
DropDownList1.DataTextField = "fullname";
|
|
|
|
|
Sorry I dont think I made myself clear..
I have already succeeded in populating my dropdown list. It shows:
"Surname, Forename"
I am referring to doing the same for a datagrid column. The column is already populated using an SQL View as shown in original post. Instead of having the column display:
"Surname"
I want it to display:
"Forename, Surname"
see what I mean ?
|
|
|
|
|
in ur view instead of surname set forename and instead of forename set surname
i.e
select ........ forename + ', ' + surname as fullname<br />
<br />
DropDownList1.DataTextField = "fullname";
|
|
|
|
|
Thank you very much for your replies..
Works now!
Turns out I had to remove the following bold entry:
SELECT ..., tblUser.Surname, ... FROM ...
and place:
tblUser.Forename + ' ' + tblUser.Surname AS Fullname instead!
Lol, Thanks.. it helped a lot. At least just to show me how trivial this was!
|
|
|
|
|
Never mind dude u are welcome...
|
|
|
|
|
Hello,
I have two tables with the following fields:
1. Table "web_Content"
Fields: [ContentId] > Primary Key;
[ContentName];
[ContentPage].
2. Table "web_ContentLocalized"
Fields: [Content_LocalizedId] > Primary Key
[ContentId] > Joined to ContentId in table "web_Content"
[ContentCulture]
[ContentHtml]
I want to INSERT a new record in both databases.
What I mean is that a new record will add values to [ContentName];
[ContentPage]; [ContentCulture] and [ContentHtml].
[ContentId] and [Content_LocalizedId] are autonumbers.
[ContentId] in table "web_ContentLocalized" should be the same as in
[ContentId] of "web_Content" table.
Anyway, I tried but until now I was able to make this work.
This is what I have:
INSERT INTO web_Content ( ContentPage, ContentName )
SELECT web_Content.ContentPage, web_Content.ContentName
FROM web_Content INNER JOIN web_ContentLocalized ON
web_Content.ContentId = web_ContentLocalized.ContentId;
Thanks,
Miguel
|
|
|
|
|
An INSERT statement can only target one table.
It is possible to target an INSERT statement to a view in SQL Server if you're prepared to create an INSTEAD OF trigger on the view, but this trigger will have to be coded to perform an INSERT into each table separately.
The general way of handling this is to use the SCOPE_IDENTITY() function to discover the identity value of the last row inserted.
You could consider creating a stored procedure:
CREATE PROC uspInsertWebContentLocalized
(
@contentName varchar(n),
@contentPage varchar(n),
@contentCulture varchar(n),
@contentHtml varchar(n)
)
AS
INSERT INTO web_Content ( ContentName, ContentPage )
VALUES ( @contentName, @contentPage )
INSERT INTO web_ContentLocalized
( ContentId, ContentCulture, ContentHtml )
VALUES
( SCOPE_IDENTITY(), @contentCulture, @contentHtml )
|
|
|
|
|
Hi,
I want to search a DataSet (dataset contains several tables) for a specific value. (Writing a login method that shall verify if the user exists and has the correct password)
I am bit confused about; DataSet, BindingSource, DataTable etc.
thanx in advance
Regards
/Christoffer
|
|
|
|
|
What specifically are you asking?
You seem to know what a DataSet is...It is a collection of DataTables.
Or are you asking about connecting to a Data Source like an access database or something? In that case you would need to research command objects, connection objects, and data adapters. I'm sure you can find a bunch of articles about connecting to a datasource here at codeproject.
|
|
|
|
|
Hi,
Thanx for your reply.
What I am a bit confused about is once you have "imported" data into the DataSet how do you search for a value in the dataset? Is there a common/standard way to do this? I think of a DataSet as an interface to the datastorage and therefor expect methods like getDataByUniqueKey(), searchForData(DataTable table) etc. I now understand that this is not the case. So should I write an interface to the DataSet? Maybe the problem is that I do not fully understand the relations between TableAdapter, BindingSource, DataSet?!
:-/
Hope this clarify the issue/question?!
cheers
/Christoffer
|
|
|
|
|
I think you've probably had trouble finding information on this because you don't really search a DataSet...You would do the search on a DataTable. There are a number of ways to perform a search on a DataTable object, I'll tell you about one. First of all, since a DataSet is a collection of DataTable objects, you can reference a table IN a DataSet like this:
dsMyDataSet.Tables("myTableName")
or, if for example you knew the table you wanted was the first table inserted into the DataSet:
dsMyDataSet.Tables(0)
So one way to search the DataTable requires that you first have a primary key constraint on the table. If you got the data for this DataSet from a data base by using a DataAdapter and doing a .Fill the constraints are not necessarily carried over into the DataSet. You may have to do something like this:
With dsMyDataSet.Tables("dtMyTable")<br />
.Constraints.Add("pk", .Columns("PrimaryKeyColumnName"), True)<br />
End With
The "pk" parm gives a name to the new contraint for referencing it later, the .Columns("PrimaryKeyColumnName") parm specifies which column in the DataTable is the primary or unique key, and the True parm specifies that this is a primary key. This works when just one column makes up your primary key, if you have more than one column as a primary key the .Columns("PrimaryKeyColumnName") parm should be replaced by an array of DataColumns from the DataTable that compose the Primary Key.
Once you are sure that your DataTable has a primary key constraint you can search for a row like this:
Dim rowFound As DataRow<br />
rowFound = dt.Rows.Find("myKeyValue")
or if your primary key is a number:
Dim rowFound As DataRow<br />
rowFound = dt.Rows.Find(1003)
I hope this helps.
|
|
|
|
|
Hi again,
That helped!
Thank you very much for taking your time and explain the solution of the problem of mine.
cheers
/Christoffer
|
|
|
|
|
I m trying to execute the following store procedure
create Procedure sp_sys_getMax
@FieldId int,
@tablename varchar(255)
as
select Max(@FieldId) from @tablename
the following error is occuring:
Must declare the table variable "@tablename".
i want one store proc for all tables. plz help me in this.
|
|
|
|