|
thanks so much. well appreciated.
Gerri
|
|
|
|
|
how can i get the time and date in the datecreated field in a data table while inserting a record?
|
|
|
|
|
You can return it as an OUT parameter if you are using a stored procedure, or do a select query on the record after you've inserted it. AFAIK there's no easier way to get this.
"A democracy is nothing more than mob rule, where fifty-one percent of the people may take away the rights of the other forty-nine." - Thomas Jefferson
"Democracy is two wolves and a lamb voting on what to have for lunch. Liberty is a well-armed lamb contesting the vote." - Benjamin Franklin
Edbert
Sydney, Australia
|
|
|
|
|
When you insert into the table, use getdate() as the value for the DateCreated field:
insert into mytesttable (MyDateField) values (getdate())
Or, to make a default value of the current datetime, in design view in the Enterprise Manager type (getdate()) in the Formula field for the table.
Or, when you create the table in the Query Analyzer, do it this way:
CREATE TABLE [MyTestTable] (
[IDColumn] [int] IDENTITY (1, 1) NOT NULL ,
[DateCreated] AS (getdate())
) ON [PRIMARY]
--EricDV Sig---------
Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them.
- Laurence J. Peters
|
|
|
|
|
Ok, I know how to start the query designer in VS2005 and I can make a query and run it and see the data, thats all good.
I can also create new stored procedures by using the server explorer to go the SP folder, right click, add new. I then type in my stored procedure and everything works fine.
However, is there a way to create stored procedures with the query builder, other than using typed datasets?
|
|
|
|
|
hi all
every time i add a column to my table with the type text or ntext all what is entered in the database is only the first 16 characters. it happened also with all my colleagues
plz help me with this problem
abdelhameed81
|
|
|
|
|
How is the column defined?
How are you inserting text into the column?
Mark
|
|
|
|
|
the column is created in the design view of the SQL enterprise manager and the data is inserted to it from an ASP.Net application
abdelhameed81
|
|
|
|
|
What is the max length of the text for the column?
I meant can you post code snippet showing how you do the insert?
Database is SQL Server?
Mark
|
|
|
|
|
FWIW text is a datatype that will be deprecated in future versions of SQL Server. Keep that in mind as you develop your tables. varchar or nvarchar are the best choice in my nosey opinion.
"We've all heard that a million monkeys banging on a million typewriters will eventually reproduce the entire works of Shakespeare. Now, thanks to the internet, we know this is not true." -- Professor Robert Silensky
|
|
|
|
|
Hello,
I have a couple questions and would really appreciate your responses.
Question:
1. If you are new to a database, is there a way that you can quickly find out relationships between the tables?
2. I need to retrieve information on all the tables in a database to find out which tables have a rowcount of more than 50,000 records then delete some record which thus reducing the table to 50,000 rows so as to make space. Is there a way to do that? and if so, what is the syntax to obtain this?
3. How can I cascade constraints when deleting records from a specific table?
I am using SQL server 2000 to accomplish this task.
Thanks
Greg
Coding makes the world go round!!!
|
|
|
|
|
Skanless wrote: 1. If you are new to a database, is there a way that you can quickly find out relationships between the tables?
There are diagrams that you can create to see the relationship between the tables.
Skanless wrote: 2. I need to retrieve information on all the tables in a database to find out which tables have a rowcount of more than 50,000 records then delete some record which thus reducing the table to 50,000 rows so as to make space. Is there a way to do that? and if so, what is the syntax to obtain this?
You can use the sysobjects table that can return the tables existing in your database, then query each table to check how many records it has and delete the ones over 50,000. I can't remember the correct syntax, I'm sure a bit of googling will do.
Skanless wrote: 3. How can I cascade constraints when deleting records from a specific table?
You need to specify the necessary constraints to the tables before deleting the record, and it will automatically trigger the deletion of child records.
"A democracy is nothing more than mob rule, where fifty-one percent of the people may take away the rights of the other forty-nine." - Thomas Jefferson
"Democracy is two wolves and a lamb voting on what to have for lunch. Liberty is a well-armed lamb contesting the vote." - Benjamin Franklin
Edbert
Sydney, Australia
|
|
|
|
|
I'm using ADO.NET and I'm attempting to get the column length for VARCHAR columns using the MaxLength property of the DataTable class, but it always returns -1, any secrets to finding this info from a returned MS SQL Server Query ?
|
|
|
|
|
According to the docs
"If the column has no maximum length, the value is –1 (default)."
If you set MaxLength on a column do you still get -1 back?
Mark
|
|
|
|
|
Yes, the length limit can be seen in the "Design Table" dialog of the SQL Server Enterprise Manager for the table in question. Its a VARCHAR(50) column, but after I query this tabkle the DataTable's DataColumn has a MaxLength value of -1
Here is the code i use to Query the Table if that helps...
DataTable DT = new DataTable();
if(m_DB is SqlConnection)
{
m_DA = new SqlDataAdapter(Query,(SqlConnection)m_DB);
m_CB = new SqlCommandBuilder((SqlDataAdapter)m_DA);
((SqlCommandBuilder)m_CB).QuotePrefix="[";
((SqlCommandBuilder)m_CB).QuoteSuffix="]";
((SqlDataAdapter)m_DA).Fill(DT);
}
|
|
|
|
|
Ok, sorry.
I use ODBC to get schema info in my database code, specifically SQLTables() and SQLColumns().
Take a look at GetSchemaTable (in DataReader). I'm pretty sure that retreives the same info
as the ODBC functions.
I think it's tough to use a specific SQL query because the way schema is stored varies by server,
version, etc.
Mark
|
|
|
|
|
hai frndz,
i am using MS office 2003.
In MSAccess Database is there any way to retrive autoincremt value just after insertion to the table like
select @@identity or select Scope_identity in MSSQL 2000.
in select @@identity some times it return 0 value.
help me plzzzzzzz
All I ever wanted is what others have....
CrazySanker
|
|
|
|
|
Well....are you talking about an 'Autonumber' field? If you are, then if your Autonumber field were something like 'ProductID' then you could say something like
SELECT Max(ProductID) FROM Product
|
|
|
|
|
Hi All,
This is my first post in this message board. I am working in ASP.NET 2.0 project using C#.
I am implementing DataAccess mechanism using 3 tier architecture.
UI:In my aspx page, i am using ObjectDataSource, in which the SELECT method is a method from my BLL(Business Logic Layer).
BLL:In this class, it accesses a method from my DAL(Data Access Layer), whose return type is DataTable.
DAL:It uses a User Stored Procedure (USP) to retrieve the DataTable, and it has some OUTPUT variables also.
The whole logic is works fine. The OUTPUT variable's values are captured in BLL class (during run time).
My Problem : I wish to access the OUTPUT variables from the ObjectDataSource's Selected event handler.How to do this?
Previously, i am directly access my DAL from my ObjectDataSource, that time the stmt e.OutputParameters["output_var"] gives me the result.
Thanks.
Regards,
Jay
|
|
|
|
|
The problem is that i didn't passed the arguments in my method in BLL as Reference Variable.
Now i am used the Reference Variable using ref keyword in C#. Now i got the result value in my ObjectDataSource's Selected event handler using e.OutputParameters["output_var"] .
Thanks.
Regards,
Jay
|
|
|
|
|
When trying to get a connection to a SQL server thro ASP.net application, if the SQL server is not running , what error usually it will throw, and how can i trace that error.
thanks,
Harsha
|
|
|
|
|
You will get the error "Sql Server does not exist or access is denied."
Mike Lasseter
|
|
|
|
|
Hi. I've had an issue come up in a program that I am working on with multiple projects in the same solution. The way I handle database connectivity is to encapsulate my database connection and my dataset in two separate class files, clsDatabase and clsQueryResults. clsDatabase evaluates a given connectionString and dataProvider to determine whether the app is using an OLEDB, SQLServer, MySQL, or Oracle database and uses the appropriate connections (i.e. OleDbConnection for Access, SQLConnection for SQLServer)
...Anyway, each of the projects that are being put together into this program were developed discretely, so each of them needed to be able to communicate with the database. Thus, clsDatabase and clsQueryResults are located in each of the programs. This causes a problem in my application because it means that I have to maintain 2 separate instances of clsDatabase (both of which connect to the same db file) which is very undesirable. What I would like to do is pull clsDatabase and clsQueryResults out of the individual project files and place them in their own library. However, for security reasons, the db methods located in clsDatabase have been given access type "internal." I would like to keep this library exposed to my projects while not disclosing it to the UI or Application layer. Does anyone know of any way to accomplish this?
For clarity:
This is how my logic looks:
UI->Application->|Project1->|Project1ClassFile->|clsDatabase->|ADO.NET
|
|Project2->|Project2ClassFile->|clsDatabase->|ADO.NET
This is how I want it to look:
UI->Application->|Project1->|Project1ClassFile->|
| |->clsDatabase->|ADO.NET
|Project2->|Project2ClassFile->|
|
|
|
|
|
Maybe I'm being too simplistic, but if you do not want to build clsDatabase into a shared dll, then can't you just use the same class files in each of the projects? I don't understand why you need to "maintain 2 separate instances of clsDatabase."
Put the shared clsDatabase classes in a separate folder. Add the class files to each project as Linked files. Then, both project1 and project2 will have the same source compiled into the application and you can continue to use the internal modifier.
See: Add Existing Item Dialog Box [^]
Add As Link Adds the existing item as a link from the project to its original location. Linking to files is useful when working in teams on shared resources; many projects can link to a file in one location.
--EricDV Sig---------
Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them.
- Laurence J. Peters
|
|
|
|
|
Using the class files in each of the projects is how the application is currently managed. The problem is that inside each of the object files inside each of the projects, linkage to the clsDatabase class is maintained inside the context of the project. So Project1.ObjectClassA 's private database connection object is a Project1.clsDatabase. Project2.ObjectClassB 's private database connection object is a Project2.clsDatabase.
My logical design goes like this:
UI->App Layer|->ObjectAList|-> ObjectClassA |->clsDatabase|->ADO.NET|->DB1
|
|->ObjectBList|-> ObjectClassB |->clsDatabase|->ADO.NET|->DB1
I don't want to have to maintain 2 logical channels to my database. I think I can elaborate better through code
At the Application Layer:
I have a "Mediator" class that handles Network connectivity and Business Logic Management. Mediator contains an instance of "Project1List" and "Project2List"
using Project1;
using Project2;
clsProject1List prjList1;
clsProject2List prjList2;
clsProject1.clsDatabase mDatabase1;
clsProject2.clsDatabase mDatabase2;
public clsMediator()
{
string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=mydatabase.mdb;";
string dataProvider = "OLEDB";
mDatabase1 = new clsDatabase(connectionString, dataProvider);
mDatabase2 = new clsDatabase(connectionString, dataProvider);
}
As you can see, I have to fetch two db connections from the connection pool when I should actually only be using one. Imagine if this were a module that aggregated 20 or 30 different busines modules that all connected to the same corporate database. .......WAY too convoluted.
The logical design I desire is:
UI->App Logic |>ObjectAList|>ObjectA|
| |>clsDatabase->ADO.NET->Database
|>ObjectBList|>ObjectB|
|
|
|
|