using

c# execute SqlCommand with Parameters in “using” code block

不问归期 提交于 2019-12-29 09:02:06
问题 I am attempting to execute an SQL Command through a 'using' code block, but can't seem to get it to work with Parameters. I get the error: 'Parameters does not exist in the current context', does anyone have a possible solution for this problem? Heres My code: DataTable dt = new DataTable(); using (var con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString)) using (var cmd = new SqlCommand(" SELECT FName" + " FROM EmployeeTable " + " WHERE

True coding convention about usings/try/catches

隐身守侯 提交于 2019-12-25 13:35:28
问题 Let's assume i got this code: internal static bool WriteTransaction(string command) { using (SqlConnection conn = new SqlConnection(SqlConnectionString)) { try { conn.Open(); using (SqlCommand cmd = new SqlCommand(command, conn)) cmd.ExecuteNonQuery(); } catch { return false; } } return true; } Well, i have placed conn's using outside the try / catch clause because SqlConnection 's constructor will not throw any exception (as it says). Therefore, conn.Open() is in the clause as it might throw

True coding convention about usings/try/catches

邮差的信 提交于 2019-12-25 13:34:58
问题 Let's assume i got this code: internal static bool WriteTransaction(string command) { using (SqlConnection conn = new SqlConnection(SqlConnectionString)) { try { conn.Open(); using (SqlCommand cmd = new SqlCommand(command, conn)) cmd.ExecuteNonQuery(); } catch { return false; } } return true; } Well, i have placed conn's using outside the try / catch clause because SqlConnection 's constructor will not throw any exception (as it says). Therefore, conn.Open() is in the clause as it might throw

Using declarations in private namespaces in header files

好久不见. 提交于 2019-12-25 07:05:55
问题 I have a template class that uses some boost functions in it's methods. Cause this class is template, it's method should be implemented in a header file. I use some using declarations to make code more readable: namespace network { namespace v1 { namespace detail { using boost::phoenix::if_; using boost::for_each; /* some more functions */ template <class T> class Some { public: Some() { for_each(inVector, /* some phoenix code */); } private: vector<int> intVector; }; } template <class T>

Outputting large XML file from SQL with Powershell

↘锁芯ラ 提交于 2019-12-25 01:16:33
问题 I have a Powershell script that calls a stored procedure in SQL server and outputs the resulting XML directly to a file. It works for a smaller test file but falls down with the full size (~1.5gb file). The stored procedure works fine. I can call it within SQL server - the problem is that I have to open it in the SQL server then manually save it to a file, then edit that file to remove newlines. When I run the script it falls down when it tries to delete the intermediary files at the end.

Using statement best practice [closed]

≯℡__Kan透↙ 提交于 2019-12-24 11:08:28
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 5 years ago . It may be a silly question, but since I can't give it an answer by my own, I will ask it here. Let we have a module that we want to use in an http handler (the web app is written in C# using ASP.NET) and let that this module implements the IDisposable interface. Then a common

Autocomplete using jsp and scriplets(Not using java classes)

元气小坏坏 提交于 2019-12-24 08:28:26
问题 I want to make an autocomplete but not by using any java method. Just by using jsp, jquery, ajax and scriplets. Is it possible? Please suggest. I tried using the code given below, but am getting error Uncaught Error: cannot call methods on autocomplete prior to initialization; attempted to call method 'List.jsp' The code is given below: //(Index.jsp) <html> <head> <script src = "https://code.jquery.com/jquery-1.10.2.js"></script> <script src = "https://code.jquery.com/ui/1.10.4/jquery-ui.js">

C++ using namespaces to avoid long paths

此生再无相见时 提交于 2019-12-24 03:55:12
问题 I am still learning C++, and I have never really created my own namespaces before. I was experimenting with them and while I got most things to work, there's one thing that I still can't seem to do. I would like to be able to call a static method within a class without typing something like NameOfClass::method . Here is what I thought the code should look like, but it fails to compile: File A.h , namespace Test { class A { public: static int foo() { return 42; } }; } File main.cpp , #include

Disposing datacontext causes Invalid attempt to call Read when reader is closed

白昼怎懂夜的黑 提交于 2019-12-24 03:42:57
问题 I'm building an MVC 2 app and using linq to sql with stored procs. I created a data access layer that has an internal datacontext class and a public class that I expose applications. In my public class I expose methods which access the datacontext class and convert the data to my own object model classes using linq. In my public class, I would expose a method using the following patter: public IEnumerable<MyObject> ListObjects(int iParameter) { using (MyDataContext db = new MyDataContext) { /

Can using be used to type alias an array?

你。 提交于 2019-12-24 01:53:48
问题 I'm not sure I've worded this properly since this is a bit of an odd situation. Basically I've found some code like this: template<class T> struct X { typedef T Type; }; template<class T> struct X<const T[]> { typedef T Type[]; } And I was in the process of changing the typedef s to use the C++11 using type-alias syntax when I realised this doesn't seem to work for the second example. i.e. it isn't possible to do: template<class T> struct X<const T[]> { using Type[] = T; } Why is this? Is