|
si_69 wrote: I am trying to create a generic method for calling stored procedures
Normally that isn't a good idea. It adds complexity and does not have a significant impact on maintenance costs.
si_69 wrote: Can anyone advise
So if you still want to do it...
1. You must create a sql statement dynamically with matching parameter place holders corresponding to those in the collection(array.) So you are creating SQL dynamically.
2. You must then create a SqlCommand with at sql. Then you populate it the parameters with the collection.
|
|
|
|
|
0) It probably shouldn't be static.
1) You should probably not keep creating the Connection and Command -- create one and hold onto it (in the closed state).
2) Where does ConnectionString come from?
3) Here's your code with a few changes. It compiles, but it's untested:
public static bool WriteToDatabase(
string sql,
System.Data.CommandType commandType,
out string errorText,
params System.Tuple<string,object>[] values
)
{
bool success = true;
errorText = null;
using (System.Data.IDbConnection connection = new System.Data.SqlClient.SqlConnection(ConnectionString))
{
try
{
using (System.Data.IDbCommand command = connection.CreateCommand() )
{
command.CommandText = sql ;
command.CommandType = commandType ;
foreach (System.Tuple<string,object> param in values )
{
System.Data.IDbDataParameter p = command.CreateParameter() ;
p.ParameterName = param.Item1 ;
p.Value = param.Item2 ;
command.Parameters.Add(p);
}
connection.Open();
command.ExecuteNonQuery();
}
}
catch ( System.Exception err )
{
success = false ;
errorText = err.ToString() ;
}
finally
{
connection.Close();
}
}
return ( success ) ;
}
WriteToDatabase
(
"blah blah blah"
,
System.Data.CommandType.Text
,
out error
,
new System.Tuple<string,object> ( "@date" , System.DateTime.Now )
) ;
|
|
|
|
|
hi everyone i was wondering how to load a textfile into textbox on a windows application, and also when it is loaded, edit the data and save any changes made via a second form. many thanks
|
|
|
|
|
|
Set the MultiLine property of TextBox to True as given here
http://msdn.microsoft.com/en-us/library/12w624ff.aspx[^]
for showing and editing multiple lines. Then the following code can be used to read all the text from the inputFile to the TextBox and then to save the modified text from the TextBox to the outputFile
TextBox1.Text = System.IO.File.ReadAllText(inputFileName);
System.IO.File.WriteAllLines(outputFileName, TextBox1.Text);
|
|
|
|
|
+5 for short and to the point answer
Happy Coding...
modified 12-Apr-12 3:06am.
|
|
|
|
|
|
You need StreamReader to read the data from file and show into text box, Here is the code snippet for that:
sr = new StreamReader(filename);
while (!sr.EndOfStream)
{
if (txtBox.Text.Trim() == "")
{
txtBox.Text = sr.ReadLine();
}
else
{
txtBox.Text = txtBox.Text + Environment.NewLine + sr.ReadLine();
}
}
Note: TextBox Should be Multiline, replace the "filename" with your file location and you must include:
using System.IO;
Now for saving the data, you need to write the text of textbox in file. For that ou need StreamWriter. For this You can take the reference from following link:
http://msdn.microsoft.com/en-us/library/8bh11f1k.aspx[^]
Happy Coding...
|
|
|
|
|
Hi all
I am having a picture box with a world map image of size 1800*3600 in it. Now I would like to create heat maps at different points based on latitude and longitude positions and the intensity of heat maps should be different for each point.
can anyone help me in designing the above said feature
thanks
|
|
|
|
|
|
The key point is, I think, to map or translate the GPS coordinates with the XY coordinates of your image.
image top left = XY (0,0) and corresponds to GPS (?, ?)
bottom right = XY (3600, 1800) and corresponds to GPS (?, ?) (assume x=3600 and y=1800)
(and everything in between).
You might want to opt to move the base (XY 0,0) with the GPS 0,0.
Hope this helps.
V.
|
|
|
|
|
Do you have a specific question?
|
|
|
|
|
I have load a xml file data to application. which is the best way to load the data 1) dataset load 2) XML Serialization 3) XMLDocument
Xml has defined data only, but have around one mb data...
|
|
|
|
|
I use XmlDocument, but it depends on your needs.
|
|
|
|
|
|
|
I want to integrate my Window application with Google Map to show the users(Which are basically locations) of my application in he Google map along with the tool tip to show whether a certain user/location has marked his attendance or not
|
|
|
|
|
|
I want to show mu users(which are basically locations) in to the google map along with the tool tip to show whether they have marked attendance or not.
|
|
|
|
|
How we can check whether exchange server is installed in a system using c#.
|
|
|
|
|
I want to store hash table in compound file.Is there any way to do that? Presently i am storing hash table in .dat file using BinaryFormatter class.
|
|
|
|
|
Member 8143513 wrote: I want to store hash table in compound file.
What is a compound file?
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
|
"
used in a variety of programs from Microsoft Word and Microsoft Access to Business Objects
"
but now they use XML.
|
|
|
|
|
Very interesting but are you sure that's what OP means?
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|