Click here to Skip to main content
15,922,166 members
Home / Discussions / Database
   

Database

 
QuestionHelp with SQL query!!! Pin
bazpaul21-Nov-06 4:51
bazpaul21-Nov-06 4:51 
AnswerRe: Help with SQL query!!! Pin
Farhan Noor Qureshi21-Nov-06 4:58
Farhan Noor Qureshi21-Nov-06 4:58 
GeneralRe: Help with SQL query!!! Pin
bazpaul21-Nov-06 5:00
bazpaul21-Nov-06 5:00 
AnswerRe: Help with SQL query!!! Pin
Eric Dahlvang21-Nov-06 9:53
Eric Dahlvang21-Nov-06 9:53 
QuestionStore Proc Problem Pin
tthellebuyck21-Nov-06 4:49
tthellebuyck21-Nov-06 4:49 
AnswerRe: Store Proc Problem Pin
Leah_Garrett21-Nov-06 17:51
Leah_Garrett21-Nov-06 17:51 
GeneralRe: Store Proc Problem Pin
tthellebuyck22-Nov-06 3:15
tthellebuyck22-Nov-06 3:15 
QuestionUnable to update the record. Pin
Arun Hegde21-Nov-06 3:58
Arun Hegde21-Nov-06 3:58 
Dear sir,
i have created a form with 3 textbox controls and a button called transfer


I have a table named CustId with the following records:

CID BAL
1 30000
2 50000

Here when i enter any amount (i.e, 3000) in TextBox1 and
enter the CID number(2) in the TextBox3 and click on the transfer button

The record bearing CID as 2 should be updated (the balance in this case will be 50000-3000=47000)
similarly,
if i enter any amount (i.e, 2000) in TextBox2 and
enter the CID number(1) in the TextBox3 and click on the transfer button

The record bearing CID as 1 should be updated (the balance in this case will be 30000-2000=32000)


i have already written the coding for that . But when i try to execute it
it gives a error , that is

"Line 1 Incorrect sytax near = "


Pl see the code below












using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;

namespace data1
{
///
/// Summary description for Form1.
///

public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.TextBox textBox2;
private System.Windows.Forms.TextBox textBox3;
private System.Windows.Forms.Button button1;
///
/// Required designer variable.
///

private System.ComponentModel.Container components = null;

public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();

//
// TODO: Add any constructor code after InitializeComponent call
//
}

///
/// Clean up any resources being used.
///

protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}



///
/// The main entry point for the application.
///

[STAThread]
static void Main()
{
Application.Run(new Form1());
}
SqlConnection cn;
SqlCommand dbcm,crcm;
string dbcmstr,crcmstr;
int i1,i2;
SqlTransaction tr;

private void button1_Click(object sender, System.EventArgs e)
{
try
{
cn = new SqlConnection("user id = sa;initial catalog=pubs");
dbcmstr = string.Format("update custdb set bal=bal-{0}where cid={1}",textBox3.Text,textBox1.Text);
crcmstr = string.Format("update custdb set bal=bal+{0}where cid={1}",textBox3.Text,textBox2.Text);
dbcm=new SqlCommand(dbcmstr,cn);
crcm=new SqlCommand(crcmstr,cn);
cn.Open();

tr=cn.BeginTransaction();

dbcm.Transaction=tr;
i1=dbcm.ExecuteNonQuery();

crcm.Transaction=tr;

i2=crcm.ExecuteNonQuery();


if(i1==1 && i2==1)
{
tr.Commit();
MessageBox.Show("sucsesfull");
}
else
{
tr.Rollback();
MessageBox.Show("Failure");
}
cn.Close();
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}

private void Form1_Load(object sender, System.EventArgs e)
{

}


}
}

pl help me out with this

Thank u very much

arun
AnswerRe: Unable to update the record. Pin
Colin Angus Mackay21-Nov-06 4:27
Colin Angus Mackay21-Nov-06 4:27 
QuestionHow to creat the registration form for Acces Pin
lopa1221-Nov-06 3:32
lopa1221-Nov-06 3:32 
AnswerRe: How to creat the registration form for Acces Pin
Paul Conrad21-Nov-06 19:39
professionalPaul Conrad21-Nov-06 19:39 
QuestionCreating a database Pin
Christer Claesson21-Nov-06 1:17
Christer Claesson21-Nov-06 1:17 
AnswerRe: Creating a database Pin
ChandraRam21-Nov-06 1:48
ChandraRam21-Nov-06 1:48 
AnswerRe: Can't connect to Mysql "godaddy" Pin
Paul Conrad21-Nov-06 19:41
professionalPaul Conrad21-Nov-06 19:41 
GeneralRe: Can't connect to Mysql "godaddy" [modified] Pin
Samuel G21-Nov-06 20:14
Samuel G21-Nov-06 20:14 
GeneralRe: Can't connect to Mysql "godaddy" Pin
Paul Conrad21-Nov-06 20:57
professionalPaul Conrad21-Nov-06 20:57 
GeneralRe: Can't connect to Mysql "godaddy" Pin
Samuel G21-Nov-06 21:29
Samuel G21-Nov-06 21:29 
QuestionError While importing Excel file in to Sql server 2005. Pin
srinivasintouch20-Nov-06 23:03
srinivasintouch20-Nov-06 23:03 
AnswerRe: Error While importing Excel file in to Sql server 2005. Pin
Paul Conrad25-Dec-06 18:19
professionalPaul Conrad25-Dec-06 18:19 
QuestionFinding a date between two dates.. [really urgent] Pin
kkadir20-Nov-06 22:15
kkadir20-Nov-06 22:15 
AnswerRe: Finding a date between two dates.. [really urgent] Pin
Colin Angus Mackay20-Nov-06 23:19
Colin Angus Mackay20-Nov-06 23:19 
GeneralRe: Finding a date between two dates.. [really urgent] Pin
kkadir20-Nov-06 23:36
kkadir20-Nov-06 23:36 
GeneralRe: Finding a date between two dates.. [really urgent] Pin
Tarakeshwar Reddy20-Nov-06 23:58
professionalTarakeshwar Reddy20-Nov-06 23:58 
GeneralRe: Finding a date between two dates.. [really urgent] Pin
Colin Angus Mackay21-Nov-06 0:09
Colin Angus Mackay21-Nov-06 0:09 
GeneralRe: Finding a date between two dates.. [really urgent] Pin
Paul Conrad21-Nov-06 20:26
professionalPaul Conrad21-Nov-06 20:26 

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.