Solved

Why This Code is not working.

Posted on 2012-03-23
2
221 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

632 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