Solved

Why This Code is not working.

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

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…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

743 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

14 Experts available now in Live!

Get 1:1 Help Now