ado.net

For a writeless transaction which is cheaper/quicker: COMMIT or ROLLBACK?

て烟熏妆下的殇ゞ 提交于 2019-12-24 02:43:14
问题 I'm using sql transactions as containers for APPLOCKS and other concurrency mechanisms and so I sometimes create transactions at various isolation levels which only read data and don't write. I believe that in these situations, logically, COMMIT and ROLLBACK have identical outcomes. For performance reasons, I'd like to know which one is cheaper/quicker for the server to execute? Is unavoidable bookkeeping required that is optimized for the COMMIT case and additional overhead for ROLLBACK even

Does Dataset.ReadXml() set all columns datatype in its table as string?

China☆狼群 提交于 2019-12-24 02:33:21
问题 Following is the code which gets xml data from web service and then dataset reads using ReadXml method. This Xml has ID and MyDate tags for each table row (so table(0) will have ID and MyDate columns) and this Xml data does not have schema associated with it. When page is loaded first time, it sorts by ID in asc order. It was working until ID was 999. When next ID came as 1000, even in ID asc, 1000 is showing before 999 in datagrid. I wanted to confirm that when dataset is loaded using

Null value parameters in where clause in ado.net

元气小坏坏 提交于 2019-12-24 02:25:22
问题 How do I have to set up an Sql command with possible null values in the where clause with parameters in Ado.net. Sql Statement: Select * from ViewSessionTarget where AgentId = @Parameter Ado.net code using (SqlConnection connection = new SqlConnection(@"my connection string")) using (SqlCommand command = new SqlCommand(sql, connection)) { connection.Open(); var parameter = command.Parameters.AddWithValue("@Parameter", DBNull.Value); parameter.DbType = DbType.Int64; SqlDataReader reader =

Remove duplicate column values from a datatable without using LINQ

我们两清 提交于 2019-12-24 02:25:17
问题 Consider my datatable, Id Name MobNo 1 ac 9566643707 2 bc 9944556612 3 cc 9566643707 How to remove the row 3 which contains duplicate MobNo column value in c# without using LINQ. I have seen similar questions on SO but all the answers uses LINQ. 回答1: The following method did what i want.... public DataTable RemoveDuplicateRows(DataTable dTable, string colName) { Hashtable hTable = new Hashtable(); ArrayList duplicateList = new ArrayList(); //Add list of all the unique item value to hashtable,

SQL Parameter for ALL

假如想象 提交于 2019-12-24 02:13:09
问题 I was wondering if there was a parameter in SQL for all (not *!) For example, I'm writing a search table now, and if the user does not input something in the text box, it would mean to ignore that specific parameter and display ALL of them for that field. I understand you could make separate OLEDB or SQL commands for each scenario and it would work, but I would just like to do it in one command where if the textbox is empty, I would just ignore it. So far, what this guy said I tried but didn

Is there no built in way to get a table's schema in ADO.NET?

若如初见. 提交于 2019-12-24 01:57:41
问题 I want to get a table's schema in order. This question and its answer is exactly my question, and what I want to do. However it feels (to me) pretty hackish, and being two years old now I was hoping that the answer was out-of-date. Is there truly still no way to get a table's schema in its native order? (e.g. ADOX's OpenSchema(adSchemaTables...) )? Subjective side-question: is this not a huge gaping hole in ADO.NET in general!? 回答1: exec sp_help '<tablename>' or select * from INFORMATION

Call SQL Function using ADO .NET

为君一笑 提交于 2019-12-24 01:51:11
问题 I want call function created in SQL Server, which receives two parameters and returns an integer. When I call stored procedure, I use the following code: sqlcmd.CommandType = CommandType.StoredProcedure sqlcmd.CommandText = "PROCEDURE_NAME" sqlcmd.Parameters.Add(New SqlClient.SqlParameter("@param1", Utilities.NothingToDBNull(user))) sqlcmd.Parameters.Add(New SqlClient.SqlParameter("@param2", Utilities.NothingToDBNull(password))) da = New SqlClient.SqlDataAdapter() da.SelectCommand = sqlcmd

Retrieve identity value from inserted record's primary key

∥☆過路亽.° 提交于 2019-12-24 01:18:55
问题 i cannot retrieve the new identity value from an inserted record(via DataAdapter.Update) in my DataRow. I'm using a strong typed Dataset as DAL. The table i want to update is joinded with other tables in the SelectCommand, hence the designer cannot automatically generate the insert-/update-/delete-commands and also it cannot "Refresh the DataTable" automatically(s. http://msdn.microsoft.com/de-de/library/dex7k4dw%28v=VS.100%29.aspx). I've tried to set AutoIncrement=true/false on the primary

How to put values from DataReader into List<T>? [duplicate]

走远了吗. 提交于 2019-12-24 01:18:01
问题 This question already has answers here : Closed 6 years ago . Possible Duplicate: How can I easily convert DataReader to List<T>? I want to put the data which is coming from datareader object in a generic list. I have done like this but it doesn't work... I am getting cast exception error in foreach row! SqlDataReader pointreader = cmd2.ExecuteReader(); var pointt = new List<int>(); while (pointreader.Read()) { foreach (int item in pointreader) { pointt.Add(item); if (pointt.Contains(point))

ASP.NET, C# How to Pass a StringQuery to a custom SQL Command

徘徊边缘 提交于 2019-12-24 00:58:32
问题 I have a slight issue, I have a ASP.NET Webforms application. I'm sending over a url?id=X were X is my database index or id. I have a C# class file to run my SQL connection and query. Here is the code: public DataTable ViewProduct(string id) { try { string cmdStr = "SELECT * Products WHERE Idx_ProductId = " + id; DBOps dbops = new DBOps(); DataTable vpTbl = dbops.RetrieveTable(cmdStr, ConfigurationManager.ConnectionStrings["MyDatabase"].ConnectionString); return vpTbl; } catch (Exception e) {