Click here to Skip to main content
15,887,472 members
Home / Discussions / C#
   

C#

 
GeneralRe: Substring / Split String help Pin
Dave Kreskowiak3-Sep-13 5:47
mveDave Kreskowiak3-Sep-13 5:47 
AnswerRe: Substring / Split String help Pin
BillWoodruff3-Sep-13 17:46
professionalBillWoodruff3-Sep-13 17:46 
AnswerRe: Substring / Split String help Pin
Forbiddenx4-Sep-13 4:59
Forbiddenx4-Sep-13 4:59 
Question"Handle" Pin
Bernhard Hiller3-Sep-13 3:07
Bernhard Hiller3-Sep-13 3:07 
AnswerRe: "Handle" Pin
Dave Kreskowiak3-Sep-13 3:49
mveDave Kreskowiak3-Sep-13 3:49 
GeneralRe: "Handle" Pin
Bernhard Hiller3-Sep-13 21:43
Bernhard Hiller3-Sep-13 21:43 
GeneralRe: "Handle" Pin
Dave Kreskowiak4-Sep-13 1:16
mveDave Kreskowiak4-Sep-13 1:16 
QuestionI can not Update my table when I want to check duplicate Records ... Pin
smh13923-Sep-13 2:00
smh13923-Sep-13 2:00 
Hi
i have two forms , first form has a datagrid to show Rows record of table and Second Form is the details of every record in dataGrid , when we double Click the row .
In the Second Form , I need to Update Records . So I check the record ("RegNo") is Duplicate for a specific Year.
Here is My code . But I couldn't Update the Records ...:
-----
try
{
if (txtFname.Text == FnameDataGrid && txtLname.Text == LnameDataGrid
&& txtRegNo.Text == RegNoDataGrid && txtYearReg.Text == YearRegDataGrid)
{
OleDbConnection ocn_Edited = new OleDbConnection(ConnectionStringEdited);
OleDbCommand ocmd_Edited = new OleDbCommand();


ocmd_Edited.CommandText = @"UPDATE RegTable SET FNAME=@p1,LNAME=@p2,
YearReg=@p3,RegNo=@p4,
WHERE YearReg=@g1
AND RegNo=@g2";
ocmd_Edited.Parameters.Clear();
ocmd_Edited.Parameters.AddWithValue("@p1", txtFname.Text);
ocmd_Edited.Parameters.AddWithValue("@p2", txtLname.Text);
ocmd_Edited.Parameters.AddWithValue("@p3", txtYearReg.Text);
ocmd_Edited.Parameters.AddWithValue("@p4", txtRegNo.Text);

ocmd_Edited.Parameters.AddWithValue("@g1", YearRegDataGrid);
ocmd_Edited.Parameters.AddWithValue("@g2", RegNoDataGrid);

ocmd_Edited.Connection = null;
ocmd_Edited.Connection = ocn_Edited;

ocn_Edited.Open();
ocmd_Edited.ExecuteNonQuery();
ocn_Edited.Close();

ocmd_Edited.Dispose();
ocn_Edited.Dispose();

MessageBox.Show(" ... This Table Updated ...");

frmShowGrd frmGrd = (frmShowGrd)Application.OpenForms["frmShowGrd"];
frmGrd.boolEdit = true;
frmGrd.FnameDataGrid_1 = txtFname.Text;
frmGrd.LnameDataGrid_1 = txtLname.Text;
frmGrd.YearRegDataGrid_1 = txtYearReg.Text;
frmGrd.RegNoDataGrid_1 = txtRegNo.Text;
this.Close();
}
else
{
OleDbConnection ocn = new OleDbConnection(ConnectionStringEdited);
strSql =@"SELECT RegNo WHERE RegNo=@s1 AND YearReg=@s2";
OleDbDataAdapter oda_Edited = new OleDbDataAdapter(strSql, ocn);
oda_Edited.SelectCommand.Parameters.Clear();
oda_Edited.SelectCommand.Parameters.AddWithValue(" @s1", txtRegNo.Text);
oda_Edited.SelectCommand.Parameters.AddWithValue(" @s2", txtYearReg.Text);
DataTable dt_Edited = new DataTable();
dt_Edited.Clear();
oda_Edited.Fill(dt_Edited);
if (dt_Edited.Rows.Count > 0)
{
MessageBox.Show("Already Exists!! ");
txtRegNo.Focus();
}
else
{
OleDbCommand ocmd_Edited02 = new OleDbCommand();
ocmd_Edited02.CommandText = @"UPDATE RegTable SET FNAME=@t1,LNAME=@t2,
YearReg=@t3,RegNo=@t4,
WHERE YearReg=@e1
AND RegNo=@e2";

ocmd_Edited02.Parameters.Clear();
ocmd_Edited.Parameters.AddWithValue("@t1", txtFname.Text);
-----

I don't don't where's my Mistake .
Plz Help Me .
Thanks

modified 3-Sep-13 8:16am.

AnswerRe: I can not Update my table when I want to check duplicate Records ... Pin
Bernhard Hiller3-Sep-13 22:47
Bernhard Hiller3-Sep-13 22:47 
GeneralRe: I can not Update my table when I want to check duplicate Records ... Pin
smh13924-Sep-13 3:27
smh13924-Sep-13 3:27 
QuestionCustomizing Solid Edge Pin
rani21072-Sep-13 20:11
rani21072-Sep-13 20:11 
AnswerRe: Customizing Solid Edge Pin
Pete O'Hanlon2-Sep-13 20:23
mvePete O'Hanlon2-Sep-13 20:23 
GeneralRe: Customizing Solid Edge Pin
rani21073-Sep-13 2:05
rani21073-Sep-13 2:05 
GeneralRe: Customizing Solid Edge PinPopular
Pete O'Hanlon3-Sep-13 2:11
mvePete O'Hanlon3-Sep-13 2:11 
GeneralRe: Customizing Solid Edge Pin
rani21073-Sep-13 2:25
rani21073-Sep-13 2:25 
GeneralRe: Customizing Solid Edge Pin
Dave Kreskowiak3-Sep-13 3:38
mveDave Kreskowiak3-Sep-13 3:38 
GeneralRe: Customizing Solid Edge Pin
Rohini Shirke3-Sep-13 18:19
Rohini Shirke3-Sep-13 18:19 
GeneralRe: Customizing Solid Edge Pin
Dave Kreskowiak4-Sep-13 1:09
mveDave Kreskowiak4-Sep-13 1:09 
AnswerRe: Customizing Solid Edge Pin
Abhinav S2-Sep-13 22:51
Abhinav S2-Sep-13 22:51 
GeneralRe: Customizing Solid Edge Pin
rani21073-Sep-13 2:07
rani21073-Sep-13 2:07 
QuestionSqlDataReader is not returning all rows Pin
NarVish2-Sep-13 0:57
NarVish2-Sep-13 0:57 
AnswerRe: SqlDataReader is not returning all rows Pin
Simon_Whale2-Sep-13 1:08
Simon_Whale2-Sep-13 1:08 
GeneralRe: SqlDataReader is not returning all rows Pin
NarVish2-Sep-13 1:37
NarVish2-Sep-13 1:37 
AnswerRe: SqlDataReader is not returning all rows Pin
Simon_Whale2-Sep-13 3:11
Simon_Whale2-Sep-13 3:11 
GeneralRe: SqlDataReader is not returning all rows Pin
NarVish2-Sep-13 5:35
NarVish2-Sep-13 5:35 

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.