how to update data from textboxes?

J

jaYPee

i have created an sqldataadapter using a wizard and i can save it
using datagrid control but don't know how to save the data from
textbox. because i have a master detail form and the master form is
populated w/ textboxes while the detail form is populated w/ datagrid
control.

in my sqldataadapter this is the commandtext in updatecommand

UPDATE Students
SET IDNo = @IDNo, LastName = @LastName, FirstName =
@FirstName, MiddleName = @MiddleName, Gender = @Gender, Address =
@Address,
[Parent/Guardian] = @Param2, ProgramID =
@ProgramID, MajorID = @MajorID, Year = @Year, Section = @Section,
DateofBirth = @DateofBirth,
PlaceofBirth = @PlaceofBirth, Scholarship =
@Scholarship, ElemSchool = @ElemSchool, ESAddress = @ESAddress,
ESSchYear = @ESSchYear,
SecSchool = @SecSchool, SSAddress = @SSAddress,
SSSchYear = @SSSchYear
WHERE (IDNo = @Original_IDNo) AND (Address = @Original_Address OR
@Original_Address IS NULL AND Address IS NULL)
AND (DateofBirth = @Original_DateofBirth OR
@Original_DateofBirth IS NULL AND DateofBirth IS
NULL) AND (ESAddress = @Original_ESAddress OR
@Original_ESAddress IS NULL AND ESAddress IS
NULL) AND (ESSchYear = @Original_ESSchYear OR
@Original_ESSchYear IS NULL AND ESSchYear IS
NULL) AND (ElemSchool = @Original_ElemSchool OR
@Original_ElemSchool IS NULL AND ElemSchool IS
NULL) AND (FirstName = @Original_FirstName OR
@Original_FirstName IS NULL AND FirstName IS
NULL) AND (Gender = @Original_Gender OR
@Original_Gender IS NULL AND Gender IS NULL) AND
(LastName = @Original_LastName OR
@Original_LastName IS NULL AND LastName IS NULL)
AND (MajorID = @Original_MajorID OR
@Original_MajorID IS NULL AND MajorID IS NULL)
AND (MiddleName = @Original_MiddleName OR
@Original_MiddleName IS NULL AND MiddleName IS
NULL) AND ([Parent/Guardian] = N'@Original_Parent/Guardian' OR
N'@Original_Parent/Guardian' IS NULL AND
[Parent/Guardian] IS NULL) AND (PlaceofBirth = @Original_PlaceofBirth
OR
@Original_PlaceofBirth IS NULL AND PlaceofBirth
IS NULL) AND (ProgramID = @Original_ProgramID OR
@Original_ProgramID IS NULL AND ProgramID IS
NULL) AND (SSAddress = @Original_SSAddress OR
@Original_SSAddress IS NULL AND SSAddress IS
NULL) AND (SSSchYear = @Original_SSSchYear OR
@Original_SSSchYear IS NULL AND SSSchYear IS
NULL) AND (Scholarship = @Original_Scholarship OR
@Original_Scholarship IS NULL AND Scholarship IS
NULL) AND (SecSchool = @Original_SecSchool OR
@Original_SecSchool IS NULL AND SecSchool IS
NULL) AND (Section = @Original_Section OR
@Original_Section IS NULL AND Section IS NULL)
AND (Year = @Original_Year OR
@Original_Year IS NULL AND Year IS NULL);
SELECT IDNo, LastName, FirstName,
MiddleName, Gender, Address, [Parent/Guardian], ProgramID, MajorID,
Year, Section, DateofBirth,
PlaceofBirth,
Scholarship, ElemSchool, ESAddress, ESSchYear, SecSchool, SSAddress,
SSSchYear
FROM Students
WHERE (IDNo = @IDNo)

now how can i change this so the the value in my textboxes will be
save when i update the sqldataadapter?

this is the code i use to save the database
SqlDataAdapter1.Update(DsStudentCourse1)
SqlDataAdapter2.Update(DsStudentCourse1)

there is no problem w/ sqldataadapter2 since i used datagrid. the only
problem is the sqldataadapter1 since i use textboxes instead of
datagrid.

thanks in advance.
 
W

William Ryan eMVP

jaYPee:

How are you binding your textboxes? If you are using a BindingContext and
using textbox1.DataBindings.Add("Text", datasetName, "FieldName"), when you
make a change to the textbox the underlying datasource should be changed as
well.
jaYPee said:
i have created an sqldataadapter using a wizard and i can save it
using datagrid control but don't know how to save the data from
textbox. because i have a master detail form and the master form is
populated w/ textboxes while the detail form is populated w/ datagrid
control.

in my sqldataadapter this is the commandtext in updatecommand

UPDATE Students
SET IDNo = @IDNo, LastName = @LastName, FirstName =
@FirstName, MiddleName = @MiddleName, Gender = @Gender, Address =
@Address,
[Parent/Guardian] = @Param2, ProgramID =
@ProgramID, MajorID = @MajorID, Year = @Year, Section = @Section,
DateofBirth = @DateofBirth,
PlaceofBirth = @PlaceofBirth, Scholarship =
@Scholarship, ElemSchool = @ElemSchool, ESAddress = @ESAddress,
ESSchYear = @ESSchYear,
SecSchool = @SecSchool, SSAddress = @SSAddress,
SSSchYear = @SSSchYear
WHERE (IDNo = @Original_IDNo) AND (Address = @Original_Address OR
@Original_Address IS NULL AND Address IS NULL)
AND (DateofBirth = @Original_DateofBirth OR
@Original_DateofBirth IS NULL AND DateofBirth IS
NULL) AND (ESAddress = @Original_ESAddress OR
@Original_ESAddress IS NULL AND ESAddress IS
NULL) AND (ESSchYear = @Original_ESSchYear OR
@Original_ESSchYear IS NULL AND ESSchYear IS
NULL) AND (ElemSchool = @Original_ElemSchool OR
@Original_ElemSchool IS NULL AND ElemSchool IS
NULL) AND (FirstName = @Original_FirstName OR
@Original_FirstName IS NULL AND FirstName IS
NULL) AND (Gender = @Original_Gender OR
@Original_Gender IS NULL AND Gender IS NULL) AND
(LastName = @Original_LastName OR
@Original_LastName IS NULL AND LastName IS NULL)
AND (MajorID = @Original_MajorID OR
@Original_MajorID IS NULL AND MajorID IS NULL)
AND (MiddleName = @Original_MiddleName OR
@Original_MiddleName IS NULL AND MiddleName IS
NULL) AND ([Parent/Guardian] = N'@Original_Parent/Guardian' OR
N'@Original_Parent/Guardian' IS NULL AND
[Parent/Guardian] IS NULL) AND (PlaceofBirth = @Original_PlaceofBirth
OR
@Original_PlaceofBirth IS NULL AND PlaceofBirth
IS NULL) AND (ProgramID = @Original_ProgramID OR
@Original_ProgramID IS NULL AND ProgramID IS
NULL) AND (SSAddress = @Original_SSAddress OR
@Original_SSAddress IS NULL AND SSAddress IS
NULL) AND (SSSchYear = @Original_SSSchYear OR
@Original_SSSchYear IS NULL AND SSSchYear IS
NULL) AND (Scholarship = @Original_Scholarship OR
@Original_Scholarship IS NULL AND Scholarship IS
NULL) AND (SecSchool = @Original_SecSchool OR
@Original_SecSchool IS NULL AND SecSchool IS
NULL) AND (Section = @Original_Section OR
@Original_Section IS NULL AND Section IS NULL)
AND (Year = @Original_Year OR
@Original_Year IS NULL AND Year IS NULL);
SELECT IDNo, LastName, FirstName,
MiddleName, Gender, Address, [Parent/Guardian], ProgramID, MajorID,
Year, Section, DateofBirth,
PlaceofBirth,
Scholarship, ElemSchool, ESAddress, ESSchYear, SecSchool, SSAddress,
SSSchYear
FROM Students
WHERE (IDNo = @IDNo)

now how can i change this so the the value in my textboxes will be
save when i update the sqldataadapter?

this is the code i use to save the database
SqlDataAdapter1.Update(DsStudentCourse1)
SqlDataAdapter2.Update(DsStudentCourse1)

there is no problem w/ sqldataadapter2 since i used datagrid. the only
problem is the sqldataadapter1 since i use textboxes instead of
datagrid.

thanks in advance.
 
G

Guest

There can be at least a couple of check I think you might do:

1) do you correctly bind DataColumns with TextBoxes' text property? If so, do you ever set in your code the Form.BindingContext.Position value?
2) (I think this one may be the source of your troubles) Did you call the Form.BindingContext.EndCurrentEdit method before DataAdapter's update?

Good Luck!
 
J

jaYPee

jaYPee:

How are you binding your textboxes? If you are using a BindingContext and
using textbox1.DataBindings.Add("Text", datasetName, "FieldName"), when you
make a change to the textbox the underlying datasource should be changed as
well.

in textbox properties i have added the DsStudentCourse1 -
Students.IDNo in databinding text properties
 
J

jaYPee

There can be at least a couple of check I think you might do:

1) do you correctly bind DataColumns with TextBoxes' text property? If so, do you ever set in your code the Form.BindingContext.Position value?
2) (I think this one may be the source of your troubles) Did you call the Form.BindingContext.EndCurrentEdit method before DataAdapter's update?

Good Luck!


don't know what u mean by binding datacolumns with textboxes. i have
already bind the textbox using the databinding text properties.
 
M

mgwalm

Crad said:
There can be at least a couple of check I think you might do:

1) do you correctly bind DataColumns with TextBoxes' text property? If so, do you ever set in your code the Form.BindingContext.Position value?
2) (I think this one may be the source of your troubles) Did you call the Form.BindingContext.EndCurrentEdit method before DataAdapter's update?

Good Luck!

2 is correct -you have to call EndCurrentEdit before the dataset is updated.

RegARDS
Michael
 
S

SQL Cafe

jaYPee said:
i have created an sqldataadapter using a wizard and i can save it
using datagrid control but don't know how to save the data from
textbox. because i have a master detail form and the master form is
populated w/ textboxes while the detail form is populated w/ datagrid
control.

in my sqldataadapter this is the commandtext in updatecommand

UPDATE Students
SET IDNo = @IDNo, LastName = @LastName, FirstName =
@FirstName, MiddleName = @MiddleName, Gender = @Gender, Address =
@Address,
[Parent/Guardian] = @Param2, ProgramID =
@ProgramID, MajorID = @MajorID, Year = @Year, Section = @Section,
DateofBirth = @DateofBirth,
PlaceofBirth = @PlaceofBirth, Scholarship =
@Scholarship, ElemSchool = @ElemSchool, ESAddress = @ESAddress,
ESSchYear = @ESSchYear,
SecSchool = @SecSchool, SSAddress = @SSAddress,
SSSchYear = @SSSchYear
WHERE (IDNo = @Original_IDNo) AND (Address = @Original_Address OR
@Original_Address IS NULL AND Address IS NULL)
AND (DateofBirth = @Original_DateofBirth OR
@Original_DateofBirth IS NULL AND DateofBirth IS
NULL) AND (ESAddress = @Original_ESAddress OR
@Original_ESAddress IS NULL AND ESAddress IS
NULL) AND (ESSchYear = @Original_ESSchYear OR
@Original_ESSchYear IS NULL AND ESSchYear IS
NULL) AND (ElemSchool = @Original_ElemSchool OR
@Original_ElemSchool IS NULL AND ElemSchool IS
NULL) AND (FirstName = @Original_FirstName OR
@Original_FirstName IS NULL AND FirstName IS
NULL) AND (Gender = @Original_Gender OR
@Original_Gender IS NULL AND Gender IS NULL) AND
(LastName = @Original_LastName OR
@Original_LastName IS NULL AND LastName IS NULL)
AND (MajorID = @Original_MajorID OR
@Original_MajorID IS NULL AND MajorID IS NULL)
AND (MiddleName = @Original_MiddleName OR
@Original_MiddleName IS NULL AND MiddleName IS
NULL) AND ([Parent/Guardian] = N'@Original_Parent/Guardian' OR
N'@Original_Parent/Guardian' IS NULL AND
[Parent/Guardian] IS NULL) AND (PlaceofBirth = @Original_PlaceofBirth
OR
@Original_PlaceofBirth IS NULL AND PlaceofBirth
IS NULL) AND (ProgramID = @Original_ProgramID OR
@Original_ProgramID IS NULL AND ProgramID IS
NULL) AND (SSAddress = @Original_SSAddress OR
@Original_SSAddress IS NULL AND SSAddress IS
NULL) AND (SSSchYear = @Original_SSSchYear OR
@Original_SSSchYear IS NULL AND SSSchYear IS
NULL) AND (Scholarship = @Original_Scholarship OR
@Original_Scholarship IS NULL AND Scholarship IS
NULL) AND (SecSchool = @Original_SecSchool OR
@Original_SecSchool IS NULL AND SecSchool IS
NULL) AND (Section = @Original_Section OR
@Original_Section IS NULL AND Section IS NULL)
AND (Year = @Original_Year OR
@Original_Year IS NULL AND Year IS NULL);
SELECT IDNo, LastName, FirstName,
MiddleName, Gender, Address, [Parent/Guardian], ProgramID, MajorID,
Year, Section, DateofBirth,
PlaceofBirth,
Scholarship, ElemSchool, ESAddress, ESSchYear, SecSchool, SSAddress,
SSSchYear
FROM Students
WHERE (IDNo = @IDNo)

now how can i change this so the the value in my textboxes will be
save when i update the sqldataadapter?

this is the code i use to save the database
SqlDataAdapter1.Update(DsStudentCourse1)
SqlDataAdapter2.Update(DsStudentCourse1)

there is no problem w/ sqldataadapter2 since i used datagrid. the only
problem is the sqldataadapter1 since i use textboxes instead of
datagrid.

thanks in advance.

Try our data controls. www.sqlcafe.net
They are currently in beta, but we will have a production version very
soon. You can bind textbox's to your underlying tables without any
work at all. All the binding, updating, adding, and deleting is done
for you. All you do is set the column property of the textbox in the
designer and the controls know how to handle the binding. Also, you
can bind other controls such as the combo box, radio button, check
box, and even picture box to table columns just by setting a property
on the control.

Thanks,

(e-mail address removed)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top