2 Replies - 2667 Views - Last Post: 18 December 2008 - 12:35 PM Rate Topic: -----

#1 raghavendra  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 20
  • Joined: 11-August 08

auto pouplate the drop down list and code for submit button

Post icon  Posted 18 December 2008 - 04:44 AM

Hi all,

I am a fresher to .net programming and i have to auto populate the drop down list from the database and also if the user needs to enter afresh data then also it should take that value.

Also i have to write a code for storing the form values into the database on a button click event. i have 3 buttons --> Save Button , Edit button, and Delete button.

i hve tried to write some code but i am not ablke to clean the exceptions raised while i am running the form.

My code goes here:

Protected Sub btn_submit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsave.Click
		myConnection = New SqlConnection("Data Source=.\Sqlexpress;Initial Catalog=HRDATA;Integrated Security=True")
		myConnection.Open()
		'cmdtype.CommandType = Data.CommandType.Text


		'myCommand = New SqlCommand("Insert into Employee Data values(ddlid.selectedItem,'" & txtname.Text & "',ddldesig.selectedItem,'" & txtcontno & "')", "myConnection")
		myCommand = New SqlCommand("Insert into Employeedata (ID,Name) values(ddlid.SelectedItem, ' & txtname.Text & ')", myConnection)

		ra = myCommand.ExecuteNonQuery()
		'MsgBox.Show("New Row Inserted" & ra)
		myConnection.Close()
	End Sub



any suggestions or any help is greatly appreciated
Thanks in advance,
Karthik.

Is This A Good Question/Topic? 0
  • +

Replies To: auto pouplate the drop down list and code for submit button

#2 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: auto pouplate the drop down list and code for submit button

Posted 18 December 2008 - 12:12 PM

You didn't provide your table structure for your database. So I am going to assume that ID is a numeric data type and Name is a VarChar.

Notice how I am concatenating the values from the TextBox and DropDownList.
myCommand = New SqlCommand("Insert into Employeedata (ID,Name) values(" & ddlid.SelectedValue & ", '" & txtname.Text & "')", myConnection)

Was This Post Helpful? 0
  • +
  • -

#3 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1639
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: auto pouplate the drop down list and code for submit button

Posted 18 December 2008 - 12:35 PM

Here's a tutorial on SQL basics in VB.NET that will give you the basics on interacting with a SQL database
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1