ado.net

Is Explicit Transaction Rollback Necessary?

*爱你&永不变心* 提交于 2021-02-17 21:11:36
问题 Many examples out there advocate explicit rollback of database transactions, along the lines of: using (var transaction = ...) { try { // do some reading and/or writing here transaction.Commit(); } catch (SqlException ex) { // explicit rollback transaction.Rollback(); } } However, I tend to do this: using (var transaction = ...) { // do some reading and/or writing here transaction.Commit(); } When an exception occurs, I'm just relying on the implicit rolling back of transactions that aren't

Ajax POST to controller action to update view model, and then reload div

百般思念 提交于 2021-02-17 17:09:32
问题 I'm still shaky with my use of ajax so there are a couple holes in my implementation here. I am trying to post to a controller action that will call a stored procedure to update my view model and then reload the div that will display the information. Ajax Post: $("#order-summary-panel").click(function(){ $.ajax({ url: '@Url.Action("GetOrderSummary", "Home")', type: 'POST', success: function() { alert("It Worked!") } }); }); Controller Action: [HttpPost] public ActionResult GetOrderSummary {

Ajax POST to controller action to update view model, and then reload div

吃可爱长大的小学妹 提交于 2021-02-17 17:08:31
问题 I'm still shaky with my use of ajax so there are a couple holes in my implementation here. I am trying to post to a controller action that will call a stored procedure to update my view model and then reload the div that will display the information. Ajax Post: $("#order-summary-panel").click(function(){ $.ajax({ url: '@Url.Action("GetOrderSummary", "Home")', type: 'POST', success: function() { alert("It Worked!") } }); }); Controller Action: [HttpPost] public ActionResult GetOrderSummary {

How do i get the data to my database using vb.net (class, module and form)

霸气de小男生 提交于 2021-02-17 06:43:06
问题 I hope the title is enough to understand my problem, I already installed whats need to run the ADO.NET, I already have a connection string in my module and data query in my class, Imports System.Data Imports System.Data.OleDb Module GlobalVariables Public sGlobalConnectionString As String Friend conString As String Public dr As OleDbDataReader Sub Main() Dim sGlobalConnectionString As New OleDb.OleDbConnection Dim sDataserver As String Dim sDatabaseName As String Dim sDatabaseConnection As

Do I need to close and dispose the SQLConnection explicitly?

只愿长相守 提交于 2021-02-10 08:04:33
问题 SqlDataReader rdr = null; con = new SqlConnection(objUtilityDAL.ConnectionString); using (SqlCommand cmd = con.CreateCommand()) { try { if (con.State != ConnectionState.Open) con.Open(); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add(Parameter); cmd.CommandText = _query; rdr = cmd.ExecuteReader(); } catch (Exception ex) { throw ex; } } In this above code, sqlconnection is opened inside the managed code. Hence, will the connection object be disposed automatically upon ending

ADO.NET Best Practices for Connection and DataAdaptor Object Scope

风格不统一 提交于 2021-02-08 13:34:11
问题 This is my first post on StackOverflow, so please be gentle... I have some questions regarding object scope for ADO.NET. When I connect to a database, I typically use code like this: OleDbConnection conn = new OleDbConnection("my_connection_string"); conn.Open(); OleDbDataAdapter adapter = new OleDbDataAdapter("SELECT * from Employees", conn); OleDbCommandBuilder cb = new OleDbCommandBuilder(adapter); DataTable dt = new DataTable(); adapter.Fill(dt); conn.Close(); conn.Dispose(); Let's say

Database interaction using C# without Entity Framework

亡梦爱人 提交于 2021-02-08 12:44:25
问题 I have been given an assignment where I need to display a form, data for which resides in various tables in Sql server. Requirement is strictly to not to use Entity framework or stored procedure. In such case, what are my options? At the moment I am running some sql queries using SqlCommand object but then things are getting really complicated when it comes to fetching relational data and then allowing user to update it from the form. What is the best way/approach in Winforms to allow view &

Disposing SqlCommand

笑着哭i 提交于 2021-02-08 02:17:28
问题 Because SqlCommand implements IDisposable , I would normally approach an ADO query as follows. using (SqlConnection connection = new SqlConnection(connectionString)) using (SqlCommand command = new SqlCommand(query, connection)) { // Execute command, etc. here } However, what if I need to execute multiple commands during a single connection? Do I really need a new using block for each command? The examples I found from Microsoft don't use a using block for SqlCommand s (or even call Dispose()

There is no row at position 0

自古美人都是妖i 提交于 2021-02-07 20:22:03
问题 cmd.CommandText = "select * from product where prod_code='" & Trim(txtprod_code.Text) & "' and branch='" & w_location & "' and avail_stock <>" & (0) & "" cmd.CommandType = CommandType.Text con.Open() da_uqc.SelectCommand = cmd cmd.Connection = con da_uqc.Fill(ds_uqc) m_qty = ds_uqc.Tables(0).Rows(0)(4) 'error da_uqc.Dispose() ds_uqc.Dispose() cmd.Dispose() Is it possible to give like this m_qty = ds_uqc.Tables(0).Rows(0)(4) ? 回答1: You're getting a run-time error denoting that there was no

A Powershell function to convert unix time to string?

ε祈祈猫儿з 提交于 2021-02-07 19:51:00
问题 I'm trying to read the date fields of Firefox places.sqlite datedase using ADO.NET and PowerShell. Obviously these fields are in Unix time. I'm looking for a conversion to .Net datetime or string Edit: I want to bind the datarow to a WPF GridView. I need either a way to do the conversion within the SQL query or some way while binding the datarows to the grid. 回答1: Something like this should put you on the right path: [TimeZone]::CurrentTimeZone.ToLocalTime(([datetime]'1/1/1970').AddSeconds(