Need help with another code question...

  • Thread starter Thread starter JJ297
  • Start date Start date
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
 
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()
 
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()
 
Back
Top