Click here to Skip to main content
15,890,512 members
Home / Discussions / C#
   

C#

 
Questionsimple memory leak Pin
Member 784572018-Apr-12 15:52
Member 784572018-Apr-12 15:52 
AnswerRe: simple memory leak Pin
Abhinav S18-Apr-12 16:53
Abhinav S18-Apr-12 16:53 
GeneralRe: simple memory leak Pin
Vipin_Arora19-Apr-12 2:39
Vipin_Arora19-Apr-12 2:39 
AnswerRe: simple memory leak Pin
Vipin_Arora18-Apr-12 19:09
Vipin_Arora18-Apr-12 19:09 
GeneralRe: simple memory leak Pin
VJ Reddy20-Apr-12 4:53
VJ Reddy20-Apr-12 4:53 
GeneralRe: simple memory leak Pin
Vipin_Arora20-Apr-12 6:17
Vipin_Arora20-Apr-12 6:17 
QuestionSearch form problem Pin
Amr Mohammed Rashad18-Apr-12 13:39
Amr Mohammed Rashad18-Apr-12 13:39 
AnswerRe: Search form problem Pin
Amr Mohammed Rashad18-Apr-12 18:31
Amr Mohammed Rashad18-Apr-12 18:31 
This is my search form code if any one have a better way to tell it to me.

Note: There might be some arabic words clearly show in MessageBox.Show() methods

public partial class FrmFind : Form
{
string seacrhChoice = "";

// Create a Connection String
string connectionString = @"Data Source=TOSHIBA-PC;Initial Catalog=smart2012;User ID=sa;
Password=Str0ngP@ssw0rd;Integrated Security=True";

private string tableName;

private string returnTableField
{
set { tableName = value; }
get { return tableName; }
}

private string column1;

private string returnColumn1
{
set { column1 = value; }
get { return column1; }
}

private string column2;

private string returnColumn2
{
set { column2 = value; }
get { return column2; }
}

public FrmFind()
{
InitializeComponent();
}

public FrmFind(string table, string argColumn1, string argColumn2)
{
InitializeComponent();

returnTableField = table;
returnColumn1 = argColumn1;
returnColumn2 = argColumn2;
} // end of 3 args constructor

bool validateUserEntry()
{
if (seacrhChoice == "")
{
MessageBox.Show("من فضلك اختر احدى اختيارات البحث");
radioButton1.Focus();
return false;
} // end of if
else if (findValueTextBox.Text.ToString().Trim() == "")
{
MessageBox.Show("من فضلك ادخل قيمة البحث المراد الأستعلام عنها");
findValueTextBox.Focus();
return false;
} // end of esle if
else
{
return true;
} // end of else
}

void search(string findValue)
{
bool validateUserEntryResult = validateUserEntry();
if(validateUserEntryResult == true)
{
string cmdString = "";
// Creat new Connection
SqlConnection sqlConnection = new SqlConnection();
sqlConnection.ConnectionString = connectionString;

if (seacrhChoice == "كود")
cmdString = @"SELECT " + returnColumn2 + " FROM " + returnTableField + " WHERE (" + returnColumn1 + "=@Param1)";
else
cmdString = @"SELECT " + returnColumn1 + " FROM " + returnTableField + " WHERE (" + returnColumn2 + "=@Param1)";

// Create the SELECT Command.
SqlCommand cmd = new SqlCommand();
cmd.CommandText = cmdString;
cmd.Connection = sqlConnection;
if (seacrhChoice == "كود")
cmd.Parameters.Add("@Param1", SqlDbType.Int).Value = findValue;
else
cmd.Parameters.Add("@Param1", SqlDbType.NVarChar).Value = findValue;

try
{
// Open Connection
sqlConnection.Open();

if (sqlConnection.State != ConnectionState.Open)
{
MessageBox.Show("فشل فى الأتصال بقاعدة البيانات");
} // end of if
else
{

findResultDataGridView.Rows.Clear();
findResultDataGridView.Rows.Add(99);

SqlDataReader dataReader = cmd.ExecuteReader();

int row = 0;
// Execute Read Query
while (dataReader.Read())
{
findResultDataGridView[0, row].Value = dataReader[0].ToString();
row++;
}
// Release all resources used by dataReader and close it.
dataReader.Dispose();
dataReader.Close();

// Close Connection
sqlConnection.Close();
sqlConnection.Dispose();
} // end of else
} // end of try
catch
{
findValueTextBox.Text = "";
} // end of catch
} // end of if
} // end of search()

private void findValueTextBox_Leave(object sender, EventArgs e)
{
search(findValueTextBox.Text);
} // end of findValueTextBox_Leave

private void radioButton1_Click(object sender, EventArgs e)
{
seacrhChoice = "كود";
findValueTextBox.Text = "";
findResultDataGridView.Rows.Clear();
findValueTextBox.ReadOnly = false;
} // end of radioButton1_Click

private void radioButton2_Click(object sender, EventArgs e)
{
seacrhChoice = "اسم";
findValueTextBox.Text = "";
findResultDataGridView.Rows.Clear();
findValueTextBox.ReadOnly = false;
} // end of radioButton2_Click

private void FrmFind_Load(object sender, EventArgs e)
{
// Creates and initializes the CultureInfo which uses the international sort.
System.Globalization.CultureInfo typeOFLanguage = new System.Globalization.CultureInfo("ar-eg");
// Gets the current input language
InputLanguage.CurrentInputLanguage = InputLanguage.FromCulture(typeOFLanguage);
findResultDataGridView.Rows.Add(99);
} // end of FrmFind_Load

} // end of public partial class FrmFind : Form

2 problems I have also in that form:

The search method checks for a radio button selection & a search value insertion so first problem is by calling the method validateUserEntry(), however, here comes the problem on the form load the textbox always gets focused and when trying to check a radio button that cause a leave event to the textbox which mean calling the search method which, in turn, call the validateUserEntry() and here is the disaster as I did not select the radio button it message me with error because of not selecting a radio button, and return message me again asking for the search value of the textbox.

Sorry again about so lenghty but trying to explain exactly what the problem is...
GeneralRe: Search form problem Pin
phil.o19-Apr-12 0:35
professionalphil.o19-Apr-12 0:35 
Questionconvert large files into byte [] Pin
abbd18-Apr-12 8:27
abbd18-Apr-12 8:27 
AnswerRe: convert large files into byte [] Pin
jschell18-Apr-12 8:53
jschell18-Apr-12 8:53 
AnswerRe: convert large files into byte [] Pin
OriginalGriff18-Apr-12 9:22
mveOriginalGriff18-Apr-12 9:22 
QuestionLambda expression tree building [Solved - I think] Pin
wizardzz18-Apr-12 7:43
wizardzz18-Apr-12 7:43 
QuestionSelecting desktop icon Pin
MitchG92_2418-Apr-12 2:32
MitchG92_2418-Apr-12 2:32 
AnswerRe: Selecting desktop icon Pin
Richard MacCutchan18-Apr-12 3:03
mveRichard MacCutchan18-Apr-12 3:03 
GeneralMessage Removed Pin
18-Apr-12 3:08
MitchG92_2418-Apr-12 3:08 
GeneralRe: Selecting desktop icon Pin
Richard MacCutchan18-Apr-12 3:26
mveRichard MacCutchan18-Apr-12 3:26 
AnswerRe: Selecting desktop icon Pin
Eddy Vluggen18-Apr-12 5:07
professionalEddy Vluggen18-Apr-12 5:07 
AnswerRe: Selecting desktop icon Pin
Richard MacCutchan18-Apr-12 5:13
mveRichard MacCutchan18-Apr-12 5:13 
QuestionHow to update in settings.settings file Pin
NarVish18-Apr-12 2:29
NarVish18-Apr-12 2:29 
AnswerRe: How to update in settings.settings file Pin
Eddy Vluggen18-Apr-12 5:03
professionalEddy Vluggen18-Apr-12 5:03 
GeneralRe: How to update in settings.settings file Pin
NarVish18-Apr-12 20:15
NarVish18-Apr-12 20:15 
AnswerRe: How to update in settings.settings file Pin
Eddy Vluggen19-Apr-12 0:23
professionalEddy Vluggen19-Apr-12 0:23 
GeneralRe: How to update in settings.settings file Pin
NarVish19-Apr-12 0:37
NarVish19-Apr-12 0:37 
AnswerRe: How to update in settings.settings file Pin
Eddy Vluggen19-Apr-12 0:53
professionalEddy Vluggen19-Apr-12 0:53 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.