Solved

Why This Code is not working.

Posted on 2012-03-23
2
203 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

861 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now