|
Write a Data Access Layer class and pass a reference to it to each Form that requires it.
|
|
|
|
|
Not even a minor sneer on DataTables and DataSets?
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
No, too early yet. And I do use DataTables (when appropriate) in mine.
I considered giving an example of building a List with a DataReader, but decided I really needed a shower.
|
|
|
|
|
PIEBALDconsult wrote: but decided I really needed a shower.
that's kind of a strange reaction to using DataTable s...
BTW, why have the old tried/true methods of database acces ssuddenly gone out of favor, and what are used in their places?
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997
|
|
|
|
|
John Simmons / outlaw programmer wrote: that's kind of a strange reaction to using DataTable s...
More in response to DataAdapter s. There, now I had to take another shower, are you happy now?
John Simmons / outlaw programmer wrote: the old tried/true methods of database acces
You mean like PRO*C and ESQL ? Or ODBC ?
John Simmons / outlaw programmer wrote: why have ... gone out of favor
Because the namby-pamby WSIWYG drag-and-drop crowd can't write decent SQL and think that everything should be an object regardless of whether or not it makes any sense for it to be.
John Simmons / outlaw programmer wrote: what are used in their places?
ADO.net is OK if you use it properly. Linq, EF, and other things that lay atop it and hide the developer's ineptitude, not so much.
I still hope to develop something like PRO*C for C#.
|
|
|
|
|
you can have classes that aren't forms. I suggest you read some of the nice database articles here on CodeProject, maybe this one: Using ADO.NET for beginners[^]
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
That does look like a good article. I guess I've never seen it before because it was posted before I joined. I'll have to read it more fully later.
|
|
|
|
|
When I have variables that need to be accessible application-wide, I keep them in a static class. Using some of your example code:
public static class Globals
{
public static string ConStr_1 = "...";
public static void MyMethod()
{
}
}
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997
|
|
|
|
|
I have done something similar to that in the past. I went as far as storing the individual connection string elements in App.config... so I don't hard code them.
|
|
|
|
|
That's not a good technique for a database connection because sometimes you need more than one -- use a regular class.
|
|
|
|
|
More than one database connection when connecting to the same database??
|
|
|
|
|
Yes, there are times when I'm reading through one connection and updating through another. Or occasionally updating on two with separate transactions.
My needs aren't typical.
|
|
|
|
|
Visual Basic modules are compiled into static class by the VB compiler and VB also gives you the (ugly) freedom to use the variables declared in Module without referencing the name of the Module itself. This was a design decision to accommodate legacy VB programmers and for backward compatibility.
The way you do it in C# is to create a static class yourself and reference the variables prefixed with the name of the static class.
|
|
|
|
|
Nice thoughts...
It Helps Me..
Thanks & Regards
PARAMU
|
|
|
|
|
Hi guys,
I devekop a c# wordAddIn project. I want to get space BEFORE generation bookmarks.I had developed a method that adds space after generating bookmarks :
public static void CreateSimpleField (string itemName, string bookmarkName, Word.Application application)
{
object index = 1;
if (application.Windows.get_Item(ref index).View.ShowBookmarks == false)
application.Windows.get_Item(ref index).View.ShowBookmarks = true;
Word.Selection currentSelection = application.Selection;
Word.Range rng = currentSelection.Range;
rng.Text = itemName;
while (application.ActiveDocument.Bookmarks.Exists(bookmarkName))
{bookmarkName += "_";}
Object range = rng;
application.ActiveDocument.Bookmarks.Add (bookmarkName, ref range);
int indexRange = rng.End + 1;
currentSelection.s.SetRange(indexRange, indexRange);
currentSelection.TypeText(" ");
}
How to transform it to get space BEFORE bookmarks?
Also, when I generate, it appears like this :
[bookmarkName]
How can I remove the accolade []????
ty
|
|
|
|
|
hello to all
I am writing an ivr program that uses kdtele component. also i use dialogic cards with version 5 that support tapi.
i have problem when the user end the connection (remote disconnect).
and i can't find if the connection still connected.
i use c# for the program so i write it here.
how can i tell that the user disconnect the handset or hangup.
i use many ways but no success
thanks for reply beforehand.
|
|
|
|
|
Never heard of it.
Your best source of information is going to be KAED Systems[^].
It's extremely unlikely anyone that has any experience with the library is going to see your post. When you have questions about 3rd party libraries, he best source of support for those libraries is the vendor who created them.
|
|
|
|
|
code is
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using RfidApiLib;
using System.IO;
using System.Data.SqlClient;
using System.Threading;
namespace Service_Ambu_Exit
{
public partial class Form1 : Form
{
RfidApi api = new RfidApi();
public int TagCnt = 0;
string ip;
string portNo;
string p_type = "";
string p1 = "";
string arr1;
int intcount = 0;
public Form1()
{
InitializeComponent();
}
private int connectReader()
{
try
{
StreamReader sr1 = new StreamReader("ipandport.txt");
string[] str2;
string[] str3;
string arr3;
arr3 = sr1.ReadLine();
str2 = arr3.Split('=');
ip = str2[1].Trim();
StreamReader sr3 = new StreamReader("ipandport.txt");
string arr2;
arr2 = sr3.ReadLine();
arr2 = sr3.ReadLine();
str3 = arr2.Split('=');
portNo = str3[1].Trim();
int status;
int port;
string s = "";
try
{
port = int.Parse(portNo);
s = ip;
}
catch (Exception)
{
logfile("Please mention the valid ip address and port in settings file.");
return 0;
}
status = api.TcpConnectReader(ip, port);
if (status != 0)
{
logfile("Connect Reader Failed.");
return 0;
}
if (ip == "172.16.100.3".Trim() || ip == "172.16.100.4".Trim())
{
p1 = "STAFF".Trim();
}
else if (ip == "172.16.100.5".Trim() || ip == "172.16.100.7".Trim() || ip == "172.16.100.6".Trim())
{
p1 = "AMBULANCE".Trim();
}
else if (ip == "172.16.100.2".Trim() || ip == "172.16.100.1".Trim())
{
p1 = "BASEMENT".Trim();
}
StreamReader sr = new StreamReader("RFSettings.txt");
string[] str1;
string arr;
arr = sr.ReadLine();
str1 = arr.Split(':');
arr1 = str1[1].Trim();
}
catch (Exception e)
{
logfile(e.Message.ToString());
} return 1;
}
private void Form1_Load(object sender, EventArgs e)
{
try
{
int i = 0;
while (i == 0)
{
i = connectReader();
// Thread.Sleep(2000);
}
logfile("Reader Connected.");
timer1.Start();
//timer2.Start();
}
catch (Exception e1)
{
logfile(e1.Message.ToString());
}
}
private void logfile(string str)
{
try
{
string month = string.Format("{0:MM}", DateTime.Now);
string year = string.Format("{0:yyyy}", DateTime.Now);
if (Directory.Exists("log/" + year + ""))
{
}
else
{
Directory.CreateDirectory("log/" + year + "");
}
if (Directory.Exists("log/" + year + "/" + month + ""))
{
}
else
{
Directory.CreateDirectory("log/" + year + "/" + month + "");
}
if (Directory.Exists("log/" + year + "/" + month + ""))
{
StreamWriter sw; //= new StreamWriter("log/" + year + "/" + month + "/RFlog.txt");
if (File.Exists("log/" + year + "/" + month + "/RFlog.txt"))
{
string str2 = DateTime.Now.ToString() + " " + str;
sw = File.AppendText("log/" + year + "/" + month + "/RFlog.txt");
sw.WriteLine(str2);
sw.Close();
}
else
{
sw = File.CreateText("log/" + year + "/" + month + "/RFlog.txt");
string str1 = DateTime.Now.ToString() + " " + str;
sw.WriteLine(str1);
sw.Close();
}
}
}
catch (Exception e)
{
}
}
private void check_status()
{
try
{
SqlConnection con = new SqlConnection(arr1);
SqlCommand com = new SqlCommand();
com.Connection = con;
com.CommandText = "EXEC TAG_ZONE_STATUS_DEMO";
SqlDataAdapter da = new SqlDataAdapter(com);
DataTable dt = new DataTable();
da.Fill(dt);
SqlCommand com1 = new SqlCommand();
com1.Connection = con;
com1.CommandText = "select * from temp_tbl";
SqlDataAdapter da1 = new SqlDataAdapter(com1);
DataSet ds = new DataSet();
da1.Fill(ds);
if (ds.Tables[0].Rows[0][0].ToString() == "ALLOW")
{
if (p1 == p_type)
{
SqlCommand com2 = new SqlCommand();
com2.Connection = con;
com2.CommandText = "UPDATE tbl_tag_reader_master SET FLAG = 1 WHERE TAG_ID = '" + ds.Tables[0].Rows[0]["TAG_ID"] + "'";
con.Open();
com2.ExecuteNonQuery();
con.Close();
api.SetOutPort(0, 0);
Thread.Sleep(2000);
api.SetOutPort(0, 1);
}
}
}
catch (Exception ex)
{
logfile(ex.Message.ToString());
int i = 0;
while (i == 0)
{
i = connectReader();
// Thread.Sleep(2000);
}
logfile("Reader Connected.Out Cmd");
timer1.Start();
}
}
private void timer1_Tick(object sender, EventArgs e)
{
try
{
intcount = intcount + 1;
api.ClearIdBuf();
int status;
byte tag_cnt = 0;
int i, j;
byte[,] isobuf = new byte[100, 12];
string s = "";
string s1 = "";
string[] s2 = null;
string s3;
byte tagflag = 0;
DateTime dt;
dt = DateTime.Now;
string dt1 = dt.ToString("yyyy-MM-dd HH:mm:ss");
status = api.EpcMultiTagIdentify(ref isobuf, ref tag_cnt, ref tagflag);
if (status != 0)
{
DllNotFoundException dl = new DllNotFoundException();
throw dl;
}
else if (tag_cnt > 0)
{
for (i = 0; i < tag_cnt; i++)
{
s1 = string.Format("NO.{0 }: ", TagCnt);
for (j = 0; j < 12; j++)
{
s = string.Format("{0:X2}", isobuf[i, j]);
s1 += s;
}
s2 = s1.Split(':');
s3 = DateTime.Now.ToString();
SqlConnection con1 = new SqlConnection(arr1);
SqlCommand com1 = new SqlCommand();
com1.Connection = con1;
com1.CommandText = "select count(*) from TBL_VEHICLE_OWNER_PERMISSION_MASTER where TAG_UID='" + s2[1].Trim() + "'";
SqlDataAdapter da23 = new SqlDataAdapter(com1);
DataTable dt23 = new DataTable();
da23.Fill(dt23);
int c23 = Int32.Parse(dt23.Rows[0][0].ToString());
if (c23 > 0)
{
SqlCommand com2 = new SqlCommand();
com2.Connection = con1;
com2.CommandText = "select PARKING_TYPE from TBL_VEHICLE_OWNER_PERMISSION_MASTER where TAG_UID='" + s2[1].Trim() + "'";
SqlDataAdapter da24 = new SqlDataAdapter(com2);
DataTable dt24 = new DataTable();
da24.Fill(dt24);
p_type = dt24.Rows[0][0].ToString();
}
else
{
p_type = "";
}
SqlCommand com;
com = new SqlCommand();
com.Connection = con1;
com.CommandText = "select * from tbl_tag_reader_master where tag_id='" + s2[1].Trim() + "' and datediff(second,timetag,'" + dt1 + "')<8";
DataTable dt12 = new DataTable();
SqlDataAdapter da12 = new SqlDataAdapter(com);
da12.Fill(dt12);
if (dt12.Rows.Count > 0)
{
}
else
{
com = new SqlCommand();
com.Connection = con1;
com.CommandText = "insert into tbl_tag_reader_master values('" + ip + "','" + s2[1].Trim() + "','" + System.DateTime.Now.ToString() + "','" + null + "','" + null + "','" + null + "','" + null + "','" + null + "','" + null + "')";
con1.Open();
com.ExecuteNonQuery();
con1.Close();
check_status();
TagCnt++;
}
}
}
if (intcount > 1800)
{
timercount2();
intcount = 0;
}
timer1.Start();
}
catch (DllNotFoundException d1)
{
logfile("Connection Broken. Reattempting Connection...");
int i = 0;
while (i == 0)
{
i = connectReader();
// Thread.Sleep(2000);
}
logfile("Reader Connected.Timer");
timer1.Start();
}
catch (Exception e1)
{
logfile(e1.Message.ToString());
int i = 0;
while (i == 0)
{
i = connectReader();
// Thread.Sleep(2000);
}
logfile("Reader Connected.Timer");
}
}
private void timer2_Tick(object sender, EventArgs e)
{
}
private void timercount2()
{
try
{
api.TcpCloseConnect();
int i = 0;
while (i == 0)
{
i = connectReader();
//Thread.Sleep(2000);
}
logfile("Reader Connected.Timer2");
}
catch (Exception e1)
{
logfile(e1.Message.ToString());
int i = 0;
while (i == 0)
{
i = connectReader();
//Thread.Sleep(2000);
}
logfile("Reader Connected.Timer2");
}
}
}
}
|
|
|
|
|
1. You should use <pre> or <code> tag to format code properly.
2. You should debug your application and try find the problem yourself. You just wrote some code, it doesn't work, so you think someone on the internet will fix it for you?
3. Connected to number 2 - you should tell us more specifically, what the problem is. "application hang" in the subject isn't telling us to much. You think we will run your code and check, where does it hang? We won't. Firstly you only gave us part of the code ("code-behind" of your form), and we don't know what controls you have on this form. Secondly, it's your job to locate the problem, and then we can tell you how to fix it. And if you can't locate the problem, than you should find at least a piece of code, that's causing it. Most of us here are willing to help, but you should show us, that you've done something to solve the problem yourself.
Don't forget to rate answer, that helped you. It will allow other people find their answers faster.
|
|
|
|
|
I tried to get the connected users by Win32_serverConnection/Win32_ServerSession
but I found out that WMI class is unable to get those users connected to my site
I only captured users connected to my computer by mstsc
Can anybody out there give me a clue?
any help would be greatly appreciated!
modified on Monday, May 9, 2011 4:33 AM
|
|
|
|
|
On your second point, if you got the code from an article, then there is a "new message" button at the bottom of that article, which causes an email to be sent to the author. They are then alerted that you wish to speak to them.
Posting this here relies on them "dropping by" and realising it is for them.
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
Manfred R. Bihy: "Looks as if OP is learning resistant."
|
|
|
|
|
I tried to do it myself, but I found out
that method can't work on my own,
thus I found a smiliar tool over here.
but I found out that it still can't work as well,
so I don't really know what's wrong with it.
is there something related to my OS?
I'm using Windows XP SP3
|
|
|
|
|
As I said: if you got this from an article, then the author of the article is the best person to help you.
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
Manfred R. Bihy: "Looks as if OP is learning resistant."
|
|
|
|
|
Thanks for your suggestions,
I can't find that ariticle anymore..
maybe the best thing I should do right now is to wait
somebody can help me with that.
|
|
|
|
|