sqlclient

c# adapter.fill dataset not working with stored procedure even though I know the parameters are returning data?

不羁的心 提交于 2019-12-11 18:05:44
问题 I have the strangest issue. The following works most of the time, however "now and again" it fails to return data, even though I have put a breakpoint for the adapter.fill statement, checked the params and executed them via SQL Management Studio which definitely returns the data :) So this is a standard c# SQL client call: SqlCommand command = new SqlCommand(); command.CommandType = CommandType.StoredProcedure; command.Connection = connection; The connection is definitely being opened ok, and

Is it possible to pass a parameter that is DB.null and set a value in the database equal to that?

大兔子大兔子 提交于 2019-12-10 23:50:01
问题 I'm pulling data from a database (1 record) and putting each value in a textbox or dropdownlist. Some of these values are DB.null. If they are, I convert each of them to "" (blank). However, once the user has modified the textboxes/dropdown list, they can "Save" the new results. My problem is this: If the user leaves something blank, I want to be able to maintain that the value is DB.null. Is there a way to do this? Also, is it possible that if there is a value in a textbox and the user

Why does SqlClient use unnecessary XML conversion while passing SqlXml?

跟風遠走 提交于 2019-12-10 17:28:56
问题 I`ve got a question about passing xml datatype to a query from C# code. First, here`s a table on SQL Server: CREATE TABLE [dbo].[XmlTable]( [id] [int] IDENTITY(1,1) NOT NULL, [dat] [xml] NOT NULL ) Second, I have an application which is written on C#. And I insert rows into the XmlTable from the application. Here`s the code: XDocument doc = new XDocument(new XElement("root", new XElement("abc", "123"), new XElement("cba", "321"))); var reader = new XmlTextReader(new StringReader(doc.ToString(

Set custom default CommandTimeout for all new Command Objects

佐手、 提交于 2019-12-10 12:31:13
问题 The default CommandTimeout value is 30 seconds. You can manually change the value on an instance of the command object by doing the following Dim cmd As New System.Data.SqlClient.SqlCommand cmd.CommandTimeout = 60 Is there a way to specify a different default value, such that all new command objects will automatically have this value within your solution when they are created? 回答1: As far as I know no, there is no way to change this default. The constructor code for a SqlCommand is this:

My label's text isn't changing on page_load asp.net

谁说我不能喝 提交于 2019-12-08 10:42:35
问题 I'm just starting out looking at asp.net. I've got this code that works in VB, but not in asp. I've put this in the page_load: Dim db_con As SqlConnection, ssql As String, db_cmd As SqlCommand, rdr As SqlDataReader db_con = New SqlConnection("Data Source=myServer;Initial Catalog=processes;User Id=usrID;Password=mypwd;") db_cmd = New SqlCommand() ssql = "SELECT * FROM command_table_links WHERE command_id = 1" db_con.Open() db_cmd.Connection = db_con db_cmd.CommandText = ssql db_cmd.CommandType

Cleaning Up Resources via Using Statement & Dispose for DataTable, SqlConnection, SqlCommand, & SqlDataAdapter

泪湿孤枕 提交于 2019-12-08 08:43:16
问题 I have to call a stored procedure and get the results. I know there are various ways of doing this (as with all programming), and that I should be cleaning up the resources by calling Dispose() and/or Close() . Reading this close or dispose question I'm thinking that I should be using the using statement and that should be enough. Below is how I'm making my call. My question is - am I over complicating this and will this clean up all of the resources? private Int32 CallStoredProcedure(Int32

TDS Error on Azure Entity Framework SQL Calls after Windows 10 April 2018 Update [duplicate]

耗尽温柔 提交于 2019-12-07 17:29:41
问题 This question already has answers here : SqlClient error after updating Windows - “The incoming tabular data stream (TDS) remote procedure call > (RPC) protocol stream is incorrect” (5 answers) Closed last year . I have the following C# code that executes against a SQL Server hosted in Azure. protected IQueryable<T> FilterUpdatedRows<T>(IQueryable<T> query, DateTime lastSyncTimestamp) where T: class, ITimestamp { return query.Where(x => x.InsertTimestamp >= lastSyncTimestamp || (x

Intermittent System.IndexOutOfRangeException when reading a field from IDataReader

↘锁芯ラ 提交于 2019-12-07 07:23:36
问题 I have a very weird problem in code that I would not expect to ever fail. It is a website with some traffic but not that huge based on AspDotNetStoreFront. Site intermittently crashes when trying to read a database field from a reader. This happen on various places on the website. An example of such code is below on the line with object pValue = rs["PropertyValueString"]; private Dictionary<string, object> GetPropertValuePairs(string userName) { string query = string.Format("select

C# Update Table using SqlCommand.Parameters

浪尽此生 提交于 2019-12-07 07:05:19
问题 I'm trying to update an MSSQL table using SqlCommand, I think it's a syntax error with my T-SQL, but here is what I have so far: SqlCommand sqlCmd = new SqlCommand("UPDATE yak_tickets SET email = @emailParam, subject = @subjectParam, text = @textParam, statusid = @statusIDParam, ticketClass = @ticketClassParam WHERE id = @ticketIDParam", sqlConn); The parameters are working as they should, however, the table never gets updated when I run the code. Any help would be appreciated =) Here is the

Cleaning Up Resources via Using Statement & Dispose for DataTable, SqlConnection, SqlCommand, & SqlDataAdapter

大城市里の小女人 提交于 2019-12-06 19:43:32
I have to call a stored procedure and get the results. I know there are various ways of doing this (as with all programming), and that I should be cleaning up the resources by calling Dispose() and/or Close() . Reading this close or dispose question I'm thinking that I should be using the using statement and that should be enough. Below is how I'm making my call. My question is - am I over complicating this and will this clean up all of the resources? private Int32 CallStoredProcedure(Int32 Id) { using (var dt = new DataTable()) { using (var conn = new SqlConnection(ConnectionString)) { using