Skip to content
Advertisement

Tag: c#

Insert datetime from C# into SQL Server database

when I try to insert datetime value into a SQL Server database I get this error: Conversion failed when converting date and/or time from character string Code: Table table has 1 datetime column called time. Edit: my table created in msSQL 2012: http://i.imgur.com/TJ3t3y7.png my real code is: Answer The actual problem here is that you’re writing the parameter inside quotes:

What does SQL Server do with a timed out request?

Suppose that I use C# to run a long running SQL Server stored procedure (lets say 30 minutes). Further suppose that I put a 1 hour timeout period on the query in C# such that if for whatever reason this SP takes longer than expected, I don’t end up monopolizing the DB. Lastly, suppose that this stored procedure has a

How can I connect C# with Db with App.config?

I need to connect C# with SQL Server database using app.config. My code is: and in app.config I have: but I get an error and I can’t fix it: ConfigurationErrorExeption was Unhandled Configuration system failed to initialize Can anyone help me please ? Answer Try: You’re referencing Conn as the connection string name but referenced it as Test1 in the

Calling Functions in SqlCommand

Can I use Sql Server functions in myCommand.CommandText and why? Answer If you mean, SQL Server user defined functions. Then, yes; you can use it normally like: The reason it works is because this is the way that functions are called in SQL Server directly.

Using GetSchemaTable() to retrieve only column names

Is it possible to use GetSchemaTable() to retrieve only column names? I have been trying to retrieve Column names (only) using this method, is it possible. This code retrieves a lot of table data unwanted, I only need a list containing column names!: Answer You need to use ExecuteReader(CommandBehavior.SchemaOnly)): SchemaOnly: The query returns column information only. When using SchemaOnly, the

How to fill Dataset with multiple tables?

I’m trying to fill DataSet which contains 2 tables with one to many relationship. I’m using DataReader to achieve this : But I’ve got only one table filled up. How do I achieve my goal – fill both tables? I would like to use DataReader instead DataAdapter, if it possible. Answer If you are issuing a single command with several

Advertisement