|
[x]
Posted via EE Mobile
|
||
Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again. |
||
| Question |
|
[x]
Attachment Details
|
||
|
[x]
The Solution Rating System
|
||
With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.
Your Input Matters If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support. Thank you! |
||
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: |
Here is DataHelper.cs
//I'll omit the usings...
namespace FinishPointLeadCollator
{
static class DataHelper
{
private static string global_connection_string = ConfigurationManager.ConnectionStrings["leadcollatordb"].ConnectionString;
public static SqlDataReader ReturnSqlDataReader(string sql)
{
SqlConnection conn = new SqlConnection(global_connection_string);
SqlCommand cmd = new SqlCommand(sql, conn);
cmd.CommandType = System.Data.CommandType.Text;
conn.Open();
SqlDataReader reader = cmd.ExecuteReader(CommandBehavior.CloseConnection);
return reader;
//do not close the connection here ... it will close when you close the reader
//back in the caller.
}
public static DataSet ReturnDataSet(string sql)
{
SqlConnection conn = new SqlConnection(global_connection_string);
SqlCommand cmd = new SqlCommand(sql, conn);
cmd.CommandType = System.Data.CommandType.Text;
conn.Open();
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
sda.Fill(ds);
conn.Close();
return ds;
}
public static DataSet RunStoredProcReturnDataSet(string tempsql)
{
using (var conn = new SqlConnection(global_connection_string))
{
//Taken from: http://davidhayden.com/blog/dave/archive/2006/01/27.aspx
//Creating a Stored Procedure Example using SQL Server Management Objects (SMO) and SQL Server 2005
//After doing a little investigation, SMO allows me to create stored procedures in SQL Server 2005 programatically in my code generator to keep me from having to manually copy and paste the scripts.
//SMO, a .NET based object model, ships with SQL Server 2005 in an assembly named Microsoft.SqlServer.Smo.dll. Some other supporting DLLs are also included in C:\Program Files\Microsoft SQL Server\90\SDK\Assemblies folder. These include Microsoft.SqlServer.ConnectionInfo.dll and Microsoft.SqlServer.SmoEnum.dll. Like any other assembly, to use SMO in your application, add reference to Microsoft.SqlServer.Smo.dll (and Microsoft.SqlServer.ConnectionInfo.dll) and begin using the SMO classes.
//Shown below is an example of creating a stored procedure, called GetClubByID, in a database, called MyDatabase. The comments pretty much tell the story.
string tem = "if exists (select 1 from dbo.sysobjects where id = object_id(N'[dbo].[SelectDataToExport]') and OBJECTPROPERTY(id , N'IsProcedure') = 1 ) begin drop procedure SelectDataToExport end";
DataHelper.RunSQLStatement(tem);
Server server = new Server(new Microsoft.SqlServer.Management.Common.ServerConnection(conn));
Database db = server.Databases["LeadCollator"];
StoredProcedure mySP = new StoredProcedure(db, "SelectDataToExport");
mySP.TextMode = false;
mySP.AnsiNullsStatus = false;
mySP.QuotedIdentifierStatus = false;
mySP.TextBody = tempsql;
mySP.Create();
SqlCommand cmd = new SqlCommand("dbo.SelectDataToExport",conn);
cmd.CommandType = System.Data.CommandType.StoredProcedure;
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
sda.Fill(ds);
conn.Close();
return ds;
}
}
public static void RunSQLStatement(string sql)
{
SqlConnection conn = new SqlConnection(global_connection_string);
SqlCommand cmd = new SqlCommand(sql, conn);
cmd.CommandType = System.Data.CommandType.Text;
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
}
public static int GetUserID(string username)
{
DataSet ds = DataHelper.ReturnDataSet("select id from userinfo where username = '" + username + "'");
int id = -1;
foreach (DataRow dr in ds.Tables[0].Rows)
{
id = Convert.ToInt32(dr[0].ToString());
}
return id;
}
public static int GetFriendlyBatchNameID(string batchfriendlyname)
{
DataSet ds = DataHelper.ReturnDataSet("select id from batchnames where friendlyname = '" + batchfriendlyname + "'");
int id = -1;
foreach (DataRow dr in ds.Tables[0].Rows)
{
id = Convert.ToInt32(dr[0].ToString());
}
return id;
}
}
}
Here is my Authentication code:
namespace FinishPointLeadCollator
{
public partial class FormAuthenticate : Form
{
private FormMainLeadCollator _fmlc;
public FormAuthenticate(FormMainLeadCollator fmlc)
{
this._fmlc = fmlc;
InitializeComponent();
}
public FormAuthenticate()
{
InitializeComponent();
}
private void buttonExitApplication_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void buttonLogin_Click(object sender, EventArgs e)
{
if(UserExists())
{
this._fmlc._username = this.textBoxUserName.Text.Trim();
Close();
}
else
{
this.textBoxUserName.Text = "";
this.textBoxUserPassword.Text = "";
MessageBox.Show("username / password combination does not exist");
}
}
private bool UserExists()
{
string tempsql = "select * from UserInfo where username = '" + this.textBoxUserName.Text.Trim() + "' and password = '" + this.textBoxUserPassword.Text.Trim() + "'";
//HERE IS WHERE THE EXCEPTION IS RAISED...
DataSet ds = DataHelper.ReturnDataSet(tempsql);
if (ds.Tables[0].Rows.Count == 0)
{
return false;
}
else
{
return true;
}
}
}
}
|
Advertisement
| Hall of Fame |