Solved

Why This Code is not working.

Posted on 2012-03-23
2
211 Views
Last Modified: 2012-03-26
The following code doesnt save the data.


Try
            con = New SqlConnection("server=admin-pc\SQLEXPRESS;database=testadms;Integrated security=true")
            cmd = New SqlCommand
            cmd.CommandType = CommandType.StoredProcedure
            cmd.Connection = con
            cmd.CommandText = "savestudent"
            If con.State = ConnectionState.Closed Then
                con.Open()
            End If
            cmd.Parameters.AddWithValue("@sname", txtsname.Text.Trim().ToUpper())
            If rbfemale.Checked = True Then
                cmd.Parameters.AddWithValue("@gender", "Female")
            End If
            If rbmale.Checked = True Then
                cmd.Parameters.AddWithValue("@gender", "Male")
            End If
            cmd.Parameters.AddWithValue("@dob", dtpdob.Value)
            cmd.Parameters.AddWithValue("@landline", txtsstdcode.Text + "-" + txtslandline.Text)
            cmd.Parameters.AddWithValue("@smobile ", txtccode.Text.Trim() + "-" + txtsmobile.Text.Trim())
            cmd.Parameters.AddWithValue("@semail", txtsemail.Text.Trim().ToUpper())
            cmd.Parameters.AddWithValue("@scaddress", txtlsaddress.Text.Trim())
            cmd.Parameters.AddWithValue("@scpincode", txtpincode.Text.Trim())
            If (CType(cmbstate.SelectedItem, DataRowView)("state").ToString() <> "--Select State--") Then

                cmd.Parameters.AddWithValue("@sstate", CType(cmbstate.SelectedItem, DataRowView)("state").ToString())
            Else
                MessageBox.Show("State is mandatory")
                cmbstate.Focus()
            End If
            If (CType(cmbdistrict.SelectedItem, DataRowView)("district").ToString() <> "--Select District--") Then
                cmd.Parameters.AddWithValue("@sdistrict", CType(cmbdistrict.SelectedItem, DataRowView)("district").ToString())
            Else
                MessageBox.Show("District is mandatory")
                cmbdistrict.Focus()
            End If
            If (CType(cmbvillagecity.SelectedItem, DataRowView)("village").ToString() <> "--Select Village--") Then
                If (CType(cmbvillagecity.SelectedItem, DataRowView)("village").ToString() = "New Village") Then
                    cmd.Parameters.AddWithValue("@scityvillage", txtanyothervillage.Text.Trim().ToUpper())
                Else

                    cmd.Parameters.AddWithValue("@scityvillage", CType(cmbvillagecity.SelectedItem, DataRowView)("village").ToString())
                End If
            End If

            cmd.Parameters.AddWithValue("@fname", txtfathername.Text.Trim.ToUpper())
            cmd.Parameters.AddWithValue("@fmobile", txtfmobile.Text.Trim.ToUpper())
            If (CType(cmblschool.SelectedItem, DataRowView)("school").ToString() <> "--Select Last School--") Then
                If (CType(cmblschool.SelectedItem, DataRowView)("school").ToString() = "New School") Then
                    cmd.Parameters.AddWithValue("@schoollastattended", txtanyotherschool.Text.Trim().ToUpper())
                Else

                    cmd.Parameters.AddWithValue("@schoollastattended", CType(cmblschool.SelectedItem, DataRowView)("school").ToString())
                End If
            End If

            cmd.Parameters.AddWithValue("@schooladdress", txtlsaddress.Text.Trim().ToUpper())
            cmd.Parameters.AddWithValue("@ru", rbrural.Checked)
            cmd.Parameters.AddWithValue("@lsstate", CType(cmblastschoolstate.SelectedItem, DataRowView)("state").ToString())
            cmd.Parameters.AddWithValue("@lsdistrict", CType(cmblastschooldistrict.SelectedItem, DataRowView)("district").ToString())
            cmd.Parameters.AddWithValue("@lastqualification", CType(cmblastqualification.SelectedItem, DataRowView)("lq").ToString())
            cmd.Parameters.AddWithValue("@courseinterested", CType(cmbcourse.SelectedItem, DataRowView)("course").ToString())
            cmd.Parameters.AddWithValue("@coursefees", txtcoursefees.Text.Trim())
            cmd.Parameters.AddWithValue("@deo", txtdeo.Text.Trim())
            cmd.Parameters.AddWithValue("@id", txtuin.Text.Trim())
            cmd.Parameters.AddWithValue("@username", login.txtusername.Text.Trim())
            cmd.Parameters.AddWithValue("@password", login.txtpassword.Text.Trim)
            cmd.ExecuteNonQuery()
            con.Close()
            MessageBox.Show("Record Saved Successfully")
        Catch
            MessageBox.Show("Error occured")
        End Try


Procedure
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
ALTER procedure [dbo].[savestudent]
@sname varchar(50),@gender varchar(50), @dob datetime, @landline varchar(50) ,
@smobile varchar(50) ,@semail varchar(50) ,@scaddress nvarchar(max),
@scpincode varchar(50) ,@sstate varchar(50) ,@sdistrict varchar(50),@scityvillage varchar(50),
@fname varchar(50) ,@fmobile varchar(50) ,@schoollastattended varchar(200),
@schooladdress varchar(5000) ,
@ru varchar(50), @lsstate varchar(50) ,@lsdistrict varchar(50),@lastqualification varchar(50) ,
@courseinterested varchar(50) ,@coursefees bigint ,@deo varchar(200),
@id bigint,@username varchar(200),@password varchar(200)
as
begin
update mststudents
set sname=@sname, gender=@gender, dob=@dob, landline=@landline,
smobile=@smobile,semail=@semail,scaddress=@scaddress,scpincode=@scpincode,
sstate=@sstate,sdistrict=@sdistrict,scityvillage=@scityvillage,
fname=@fname,fmobile=@fmobile,
schoollastattended=@schoollastattended,
schooladdress=@schooladdress,ru=@ru,
lsstate=@lsstate,lsdistrict=@lsdistrict,
lastqualification=lastqualification,
courseinterested=courseinterested,
coursefees=coursefees,
deo=deo,
status='Pending',
feeddate=getdate()
where id=@id and username=@username and password=@password and sstatus='Passive'
end
0
Comment
Question by:searchsanjaysharma
2 Comments
 
LVL 96

Accepted Solution

by:
Bob Learned earned 500 total points
ID: 37758195
Things to think about:

1) The connection string points to a datasource.  You need to make sure that you are looking in the same place to see if something changes

2) The stored procedure has a WHERE clause, so you need to make sure that you are meeting the criteria, or nothing gets updated.

3) Does that method get called?
0
 

Author Closing Comment

by:searchsanjaysharma
ID: 37767289
ok
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question