Solved

Why This Code is not working.

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB.net capture  result of a SQL query in variables 3 20
Open a link in vb.net 2 15
Convert Ctime to date time in textfile? 7 30
Groupbox Control ? 2 17
If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
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…

809 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