Need help with another code question...

J

JJ297

I have two textboxes on the page...shipdate and duedate. When the
page loads, shipdate has today's date loaded and duedate has a date
that's 28 days later than today. When I change the dates and submit
it's not updating in the database instead I'm getting the two dates in
pageload.

I am getting this error message when I change the duedate. What am I
doing wrong?

ExecuteNonQuery requires an open and available Connection. The
connection's current state is closed.

This is what I have

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load

If Not Page.IsPostBack Then

ShipDateTxt.Text = Today()

DueDateTxt.Text = DateAdd(DateInterval.Day, 28, Today())

End If

End Sub

Protected Sub LoanRequest_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles LoanRequest.Click
Dim conn As New
Data.SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings("TrainUserConnectionString").ConnectionString)

Dim cmd As New Data.SqlClient.SqlCommand With cmd
..Connection = conn

..CommandType = Data.CommandType.StoredProcedure

..CommandText = "UpdateloanerInfo"

..Parameters.AddWithValue("@requestorid",
Integer.Parse(Request.QueryString("requestorid")))
..Parameters.AddWithValue("@shipdate", ShipDateTxt.Text)
..Parameters.AddWithValue("@duedate", DueDateTxt.Text)
cmd.ExecuteNonQuery()
conn.Open()


End With

labeloutcome.Text = "Your entry was submitted into the database."

End sub
 
J

JJ297

I have two textboxes on the page...shipdate and duedate.  When the
page loads, shipdate has today's date loaded and duedate has a date
that's 28 days later than today.  When I change the dates and submit
it's not updating in the database instead I'm getting the two dates in
pageload.

I am getting this error message when I change the duedate.  What am I
doing wrong?

ExecuteNonQuery requires an open and available Connection. The
connection's current state is closed.

This is what I have

 Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load

If Not Page.IsPostBack Then

ShipDateTxt.Text = Today()

DueDateTxt.Text = DateAdd(DateInterval.Day, 28, Today())

End If

End Sub

Protected Sub LoanRequest_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles LoanRequest.Click
Dim conn As New
Data.SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings("TrainU­serConnectionString").ConnectionString)

Dim cmd As New Data.SqlClient.SqlCommand With cmd
.Connection = conn

.CommandType = Data.CommandType.StoredProcedure

.CommandText = "UpdateloanerInfo"

.Parameters.AddWithValue("@requestorid",
Integer.Parse(Request.QueryString("requestorid")))
.Parameters.AddWithValue("@shipdate", ShipDateTxt.Text)
.Parameters.AddWithValue("@duedate", DueDateTxt.Text)
cmd.ExecuteNonQuery()
conn.Open()

End With

labeloutcome.Text = "Your entry was submitted into the database."

 End sub

Never mind had to move conn.open in front of cmd.executenonquery()
 
J

Jeff Dillon

Perhaps the ordering is wrong here? :)

cmd.ExecuteNonQuery()
conn.Open()

I have two textboxes on the page...shipdate and duedate. When the
page loads, shipdate has today's date loaded and duedate has a date
that's 28 days later than today. When I change the dates and submit
it's not updating in the database instead I'm getting the two dates in
pageload.

I am getting this error message when I change the duedate. What am I
doing wrong?

ExecuteNonQuery requires an open and available Connection. The
connection's current state is closed.

This is what I have

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load

If Not Page.IsPostBack Then

ShipDateTxt.Text = Today()

DueDateTxt.Text = DateAdd(DateInterval.Day, 28, Today())

End If

End Sub

Protected Sub LoanRequest_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles LoanRequest.Click
Dim conn As New
Data.SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings("TrainU­serConnectionString").ConnectionString)

Dim cmd As New Data.SqlClient.SqlCommand With cmd
.Connection = conn

.CommandType = Data.CommandType.StoredProcedure

.CommandText = "UpdateloanerInfo"

.Parameters.AddWithValue("@requestorid",
Integer.Parse(Request.QueryString("requestorid")))
.Parameters.AddWithValue("@shipdate", ShipDateTxt.Text)
.Parameters.AddWithValue("@duedate", DueDateTxt.Text)
cmd.ExecuteNonQuery()
conn.Open()

End With

labeloutcome.Text = "Your entry was submitted into the database."

End sub

Never mind had to move conn.open in front of cmd.executenonquery()
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top