Hi,
Im using ASP.NET and SQL Server. While inserting the data at run time. the same data , what ever is already in database is being stored again. Say for example, i have empname and empno, "Mala" and 123 already stored in database, if i give new data "Bala" and 124, as soon as i click in insert button, the data's are stored. but Mala and 123 is stored . Even i f i give anyother data. 4 or 5 data i store, again 4 or 5 times the same data repeatedly being stored.
i.e. Mala and 123 is in database for 5 to 6 times. i donno whats wrong with my code.
My code is
Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports System.Data.OleDb
Inherits System.Web.UI.Page
Dim con As SqlConnection
Dim cmd As SqlCommand
Dim cmb As SqlCommandBuilder
Dim adp As SqlDataAdapter
Dim data As DataSet3
Dim dr As DataRow
Dim selct, uptext As String
In Page_Load
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Try
con = New SqlConnection("Data Source=ACER;Initial Catalog=preethi;Integrated Security=True")
con.Open()
selct = "select * from cooldrinks"
adp = New SqlDataAdapter(selct, con)
data = New DataSet3()
adp.Fill(data, "cooldrinks")
fillcontrols()
Catch ex As Exception
Response.Write(ex.Message)
End Try
End Sub
Private Sub fillcontrols()
TextBox1.Text = data.Tables(0).Rows(0).Item(0)
TextBox2.Text = data.Tables(0).Rows(0).Item(1)
TextBox3.Text = data.Tables(0).Rows(0).Item(2)
End Sub
Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
clearcontrols()
End Sub
Private Sub clearcontrols()
TextBox1.Text = " "
TextBox2.Text = " "
TextBox3.Text = " "
TextBox4.Text = " "
TextBox1.Focus()
End Sub
Protected Sub Insert_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim Ssql As String
Ssql = "insert into cooldrinks(drinkname,color,price)values(@drinkname,@color,@price)"
cmd = New SqlCommand(Ssql, con)
cmd.Parameters.AddWithValue("@drinkname", TextBox1.Text)
cmd.Parameters.AddWithValue("@color", TextBox2.Text)
cmd.Parameters.AddWithValue("@price", TextBox3.Text)
cmd.ExecuteNonQuery()
Response.Write("One Record inserted Successfully")
End Sub
Can any one please help me , to solve this?