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

C#

 
AnswerRe: How can we keep calling OnStart() in Started condition of Windows Service in C# Pin
Jaffer Mumtaz14-Oct-08 19:55
Jaffer Mumtaz14-Oct-08 19:55 
AnswerRe: How can we keep calling OnStart() in Started condition of Windows Service in C# Pin
#realJSOP14-Oct-08 23:32
professional#realJSOP14-Oct-08 23:32 
QuestionDeletegate Pin
San14-Oct-08 18:29
San14-Oct-08 18:29 
AnswerRe: Deletegate Pin
Guffa14-Oct-08 23:29
Guffa14-Oct-08 23:29 
Questionsave to the database.please help.sos Pin
sakis2414-Oct-08 16:38
sakis2414-Oct-08 16:38 
AnswerRe: save to the database.please help.sos Pin
Expert Coming14-Oct-08 17:42
Expert Coming14-Oct-08 17:42 
AnswerRe: save to the database.please help.sos Pin
Ashfield14-Oct-08 21:30
Ashfield14-Oct-08 21:30 
AnswerRe: save to the database.please help.sos Pin
sakis2415-Oct-08 2:06
sakis2415-Oct-08 2:06 
here is the comands
private void InitializeCommands()
{
//INSERT
dataAdapter.InsertCommand = conn.CreateCommand();
dataAdapter.InsertCommand.CommandText =
"SET IDENTITY_INSERT Producer ON insert into Producer(Pid,AFM,LastName,FirstName,City,ZipCode,Adress) values(@Pid,@AFM,@LastName,@FirstName,@City,@ZipCode,@Adress)";
AddParams(dataAdapter.InsertCommand, "Pid", "AFM", "LastName", "FirstName", "City", "ZipCode", "Adress");

//UPDATE
dataAdapter.UpdateCommand = conn.CreateCommand();
dataAdapter.UpdateCommand.CommandText =
"update Producer set AFM=@AFM, LastName=@LastName, FirstName=@FirstName, City=@City, ZipCode=@ZipCode, Adress=@Adress where Pid=@Pid ";
AddParams(dataAdapter.UpdateCommand, "Pid", "AFM", "LastName", "FirstName", "City", "ZipCode", "Adress");

//DELETE
dataAdapter.DeleteCommand = conn.CreateCommand();
dataAdapter.DeleteCommand.CommandText =
"delete from Producer where Pid = @Pid";
AddParams(dataAdapter.DeleteCommand, "Pid");
}



the add paremateres method
private void AddParams(SqlCommand cmd, params string[] cols)
{
foreach (string col in cols)
{
cmd.Parameters.Add("@" + col, SqlDbType.NVarChar, 0, col);

}

}


the insert button
private void btnAdd_Click(object sender, EventArgs e)
{

insertRec = true;
DataRow row = dt.NewRow();
dt.Rows.Add(row);
//MessageBox.Show(totalRec.ToString());
totalRec = dt.Rows.Count;
curRec = totalRec-1;
row["Pid"] = totalRec;

txtpid.Text = totalRec.ToString();
txtAFM.Text = "";
txtln.Text = "";
txtfn.Text = "";
txtCity.Text = "";
txtZip.Text = "";
txtAdr.Text = "";
btnSave.Enabled = true;
}






and the save button
private void btnSave_Click_1(object sender, EventArgs e)
{

DataRow row = dt.Rows[curRec];
//MessageBox.Show(totalRec.ToString());
//MessageBox.Show(curRec.ToString());

row.BeginEdit();
row["Pid"] = txtpid.Text;
row["AFM"] = txtAFM.Text;
row["LastName"] = txtln.Text;
row["FirstName"] = txtfn.Text;
row["City"] = txtCity.Text;
row["ZipCode"] = txtZip.Text;
row["Adress"] = txtAdr.Text;
row.EndEdit();



dataAdapter.Update(ds, "buffer");

ds.AcceptChanges();

CreateDir();

ToggleControls(true);
insertRec = !true;
}


i havevreated the dataset,dataadapter, the conection string and the datatable of course
Questiondatabase password Pin
reza assar14-Oct-08 13:27
reza assar14-Oct-08 13:27 
AnswerRe: database password Pin
martin_hughes14-Oct-08 13:33
martin_hughes14-Oct-08 13:33 
GeneralRe: database password Pin
Pete O'Hanlon15-Oct-08 4:04
mvePete O'Hanlon15-Oct-08 4:04 
GeneralRe: database password Pin
martin_hughes15-Oct-08 12:58
martin_hughes15-Oct-08 12:58 
QuestionString parsing? Pin
Rafone14-Oct-08 11:43
Rafone14-Oct-08 11:43 
AnswerRe: String parsing? Pin
nofacts14-Oct-08 11:55
nofacts14-Oct-08 11:55 
GeneralRe: String parsing? Pin
Rafone15-Oct-08 11:00
Rafone15-Oct-08 11:00 
AnswerRe: String parsing? Pin
martin_hughes14-Oct-08 12:24
martin_hughes14-Oct-08 12:24 
GeneralRe: String parsing? Pin
Paul Conrad14-Oct-08 12:44
professionalPaul Conrad14-Oct-08 12:44 
GeneralRe: String parsing? Pin
Rafone15-Oct-08 11:01
Rafone15-Oct-08 11:01 
QuestionControlling cursor and retrigger in text box event handler Pin
nofacts14-Oct-08 11:18
nofacts14-Oct-08 11:18 
AnswerRe: Controlling cursor and retrigger in text box event handler Pin
Jimmanuel14-Oct-08 12:34
Jimmanuel14-Oct-08 12:34 
GeneralRe: Controlling cursor and retrigger in text box event handler Pin
nofacts14-Oct-08 12:47
nofacts14-Oct-08 12:47 
QuestionMerging to databases Pin
postonoh14-Oct-08 10:16
postonoh14-Oct-08 10:16 
Questionvisual c++ runtine error while using c#.net Pin
balu1234514-Oct-08 7:17
balu1234514-Oct-08 7:17 
AnswerRe: visual c++ runtine error while using c#.net Pin
KaptinKrunch14-Oct-08 7:23
KaptinKrunch14-Oct-08 7:23 
Questionvirtual memory fragmentation Pin
arcabid14-Oct-08 7:16
arcabid14-Oct-08 7:16 

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.