Click here to Skip to main content
15,897,371 members
Home / Discussions / C#
   

C#

 
AnswerRe: 0=48?? Pin
Giorgi Dalakishvili3-Jul-07 21:59
mentorGiorgi Dalakishvili3-Jul-07 21:59 
GeneralRe: 0=48?? Pin
Manfr3d4-Jul-07 1:03
Manfr3d4-Jul-07 1:03 
AnswerRe: 0=48?? Pin
mav.northwind3-Jul-07 22:08
mav.northwind3-Jul-07 22:08 
GeneralRe: 0=48?? Pin
Manfr3d4-Jul-07 1:11
Manfr3d4-Jul-07 1:11 
GeneralRe: 0=48?? [modified] Pin
Martin#4-Jul-07 1:30
Martin#4-Jul-07 1:30 
GeneralRe: 0=48?? Pin
Vikram A Punathambekar4-Jul-07 1:54
Vikram A Punathambekar4-Jul-07 1:54 
Questionusing serial port with vista??? Pin
Mir_As3-Jul-07 21:38
Mir_As3-Jul-07 21:38 
Questionpassing data Pin
Bong M.3-Jul-07 21:27
Bong M.3-Jul-07 21:27 
I am a newbie, and I am starting to use the C# language, and I need a little help.

Here goes:

Main Form:
I put a textbox where card number should be inputted. When the user presses the Enter key it should look into the database (table) the value of the textbox.

Condition is:
If only one (1) item found, the information will be displayed on the Main Form other textboxes.

Otherwise if two or more items found, it will pass the card number to Form 2.

Form 2: will be shown if Main Form calls
Receive the card number passed by Main Form and search again the database (table) and display the items found on the datagridview. Then the user should select one (1) item, and pass back the single item with the complete (full) card number selected on the Main Form.

My questions:
How will I get the value of the current cell that I selected?
How will I pass back the value I selected to the Main Form?
How will Main Form receive the data being passed by Form 2?

Many thanks!

Form 1:
public partial class MRRMainForm : Form
{ // start partial class MRRMainForm
public String myConString = @"Provider=VFPOLEDB.1;" +
@"Data Source=" + D:\\MyMaintable.DBF";
public String cardNumber;

OleDbConnection con;
OleDbDataAdapter da;
OleDbCommand cmd = new OleDbCommand();
DataSet ds = new DataSet();
String commandSearch;

public MRRMainForm()
{
InitializeComponent();
}

private void txtCardNumber_KeyDown(object sender, KeyEventArgs e)
{
switch (e.KeyCode)
{
// will trap other keys later..
//case Keys.
// break;
case Keys.Enter:
findCardNumber();
txtDescription.Focus();
break;
} // end switch
}

private void findCardNumber()
{
commandSearch = "Select * from MyMaintable where substr(prod_code,6,7)=\"" + txtCardNumber.Text + "\"";
con = new OleDbConnection(myConString);
cmd.CommandText = commandSearch;
cmd.Connection = con;

con.Open();
cmd.ExecuteNonQuery();
da = new OleDbDataAdapter(cmd);
da.Fill(ds);

if (ds.Tables[0].Rows.Count > 0)
{
if (ds.Tables[0].Rows.Count > 1)
{
cardNumber = txtCardNumber.Text;
MultiplesFound myMF = new MultiplesFound(cardNumber);
myMF.myCardNumber = cardNumber;
myMF.ShowDialog();
}
else
{
txtProductCode.DataBindings.Add("text", ds.Tables[0], "prod_code");
txtDescription.DataBindings.Add("text", ds.Tables[0], "prod_desc");
txtModelNumber.DataBindings.Add("text", ds.Tables[0], "model_no");
}
}
else
{
MessageBox.Show("Not exist", "Alert", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}

} // end partial class MRRMainForm : Form


Form 2:
public partial class MultiplesFound : Form
{
public MultiplesFound(String myCard)
{
InitializeComponent();
}
public String myCardNumber;

private void MultiplesFound_Load(object sender, EventArgs e)
{
OleDbConnection con;
OleDbDataAdapter da;
OleDbCommand cmd = new OleDbCommand();
DataSet ds = new DataSet();
String commandSearch;
String myConString = @"Provider=VFPOLEDB.1;" +
@"Data Source=" + "D:\\ MyMaintable.DBF";

textBox1.Text = myCardNumber;

commandSearch = "Select * from MyMaintable where substr(prod_code,6,7)=\"" + myCardNumber + "\"";
con = new OleDbConnection(myConString);
cmd.CommandText = commandSearch;
cmd.Connection = con;

con.Open();
cmd.ExecuteNonQuery();
da = new OleDbDataAdapter(cmd);
da.Fill(ds);

dataGridView1.AutoGenerateColumns = false;
int newColIndex = dataGridView1.Columns.Add("prod_code","Code");
dataGridView1.Columns[newColIndex].DataPropertyName ="prod_code";
newColIndex = dataGridView1.Columns.Add("prod_desc","Description");
dataGridView1.Columns[newColIndex].DataPropertyName = "prod_desc";
newColIndex = dataGridView1.Columns.Add("model_no", "Model Number");
dataGridView1.Columns[newColIndex].DataPropertyName = "model_no";
dataGridView1.Columns["prod_code"].Frozen = true;
dataGridView1.DataSource = ds.Tables[0];

}

private void btnOK_Click(object sender, EventArgs e)
{
// I’m lost here!
}

private void dataGridView1_DoubleClick(object sender, EventArgs e)
{
// I’m lost here, either!
}

} //end class


BM

AnswerRe: passing data Pin
JacquesDP3-Jul-07 22:18
JacquesDP3-Jul-07 22:18 
AnswerRe: passing data Pin
wasife4-Jul-07 0:04
wasife4-Jul-07 0:04 
AnswerRe: passing data Pin
JeffPClark4-Jul-07 8:33
JeffPClark4-Jul-07 8:33 
QuestionGridview error Pin
kankeyan3-Jul-07 21:18
kankeyan3-Jul-07 21:18 
AnswerRe: Gridview error Pin
Vikram A Punathambekar3-Jul-07 22:09
Vikram A Punathambekar3-Jul-07 22:09 
GeneralHere is the code Pin
kankeyan3-Jul-07 22:19
kankeyan3-Jul-07 22:19 
GeneralRe: Here is the code Pin
Vikram A Punathambekar3-Jul-07 23:23
Vikram A Punathambekar3-Jul-07 23:23 
AnswerRe: Gridview error Pin
_AK_3-Jul-07 23:09
_AK_3-Jul-07 23:09 
QuestionDelete a string from a string array. Pin
Praveen0293-Jul-07 21:14
Praveen0293-Jul-07 21:14 
AnswerRe: Delete a string from a string array. Pin
Giorgi Dalakishvili3-Jul-07 21:26
mentorGiorgi Dalakishvili3-Jul-07 21:26 
AnswerRe: Delete a string from a string array. Pin
V.3-Jul-07 21:27
professionalV.3-Jul-07 21:27 
AnswerRe: Delete a string from a string array. Pin
Martin#3-Jul-07 21:36
Martin#3-Jul-07 21:36 
GeneralRe: Delete a string from a string array. Pin
Giorgi Dalakishvili3-Jul-07 21:51
mentorGiorgi Dalakishvili3-Jul-07 21:51 
GeneralRe: Delete a string from a string array. Pin
Martin#3-Jul-07 22:01
Martin#3-Jul-07 22:01 
GeneralRe: Delete a string from a string array. Pin
Praveen0293-Jul-07 22:01
Praveen0293-Jul-07 22:01 
GeneralRe: Delete a string from a string array. Pin
Martin#4-Jul-07 5:47
Martin#4-Jul-07 5:47 
AnswerRe: Delete a string from a string array. Pin
mav.northwind3-Jul-07 22:03
mav.northwind3-Jul-07 22:03 

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.