sqlqrystrng = "UPDATE temp_user_details set user_name = #username, user_email = #useremail, user_contact = #usercontact, user_address=#useraddress WHERE user_id = #userida"
sqlqrystrng2 = "UPDATE user_type set user_password = #userpassword where user_id = #useridb"
string_cnct = sqlqrystrng & sqlqrystrng2
conn.open
cmd = New SqlCommand(string_cnct, conn)
cmd.Parameters.Add(cmd.CreateParameter).ParameterName = "#userida"
cmd.Parameters.Add(cmd.CreateParameter).ParameterName = "#useridb"
cmd.Parameters.Item("#userida").Value = struserid
cmd.Parameters.Item("#useridb").Value = struserid
sqlqrystrng = "UPDATE temp_user_details set user_name = #username, user_email =
useremail, user_contact = #usercontact, user_address=#useraddress WHERE user_id =
userida"
sqlqrystrng2 = " UPDATE user_type set user_password = #userpassword where user_id = #useridb"
string_cnct = sqlqrystrng & sqlqrystrng2
conn.open
cmd = New SqlCommand(string_cnct, conn)
cmd.Parameters.Add(cmd.CreateParameter).ParameterName = "#userida"
cmd.Parameters.Add(cmd.CreateParameter).ParameterName = "#useridb"
cmd.Parameters.Item("#userida").Value = struserid
cmd.Parameters.Item("#useridb").Value = struserid
You need to add space before Update in second string
Related
I have implemented a RangeBar for a Gantt style chart with data from SQL Server:
mySelectQuery = "SELECT [DateTime] as StartDate, DATEADD(Day, [Time], [DateTime]) as EndDate, [Type] FROM [TaskTrack] WHERE [User] = '" + User.Identity.Name + "' AND DATEADD(Day, [Time], [DateTime]) >= getdate() ORDER BY [DateTime]";
string connStr = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;
SqlConnection conn = new SqlConnection(connStr);
DataSet ds = new DataSet();
dynamic adapter = new SqlDataAdapter(mySelectQuery, conn);
conn.Open();
adapter.Fill(ds);
Chart1.DataSource = ds;
Chart1.Series["Series1"].ChartType = System.Web.UI.DataVisualization.Charting.SeriesChartType.RangeBar;
Chart1.Series["Series1"].Label = "";
Chart1.Series["Series1"].XValueMember = "Type";
Chart1.Series["Series1"].YValueMembers = "StartDate,EndDate";
Chart1.Series["Series1"].ToolTip = "#VALY : #VALX";
Chart1.Series["Series1"].SmartLabelStyle.Enabled = true;
Chart1.ChartAreas["ChartArea1"].AxisX.LabelStyle.Enabled = false;
Chart1.ChartAreas["ChartArea1"].AxisX.MajorGrid.Enabled = false;
Chart1.ChartAreas["ChartArea1"].AxisY.MajorGrid.Enabled = false;
Chart1.DataBind();
conn.Close();
This works really well but along the X Axis are dates and I would like to have a vertical red line pointing up to denote todays date so that when looking at the chart it gives a good indication of when today is and what is to be done for the future.
Does anyone have an example of how to do this?
So if anyone is getting this issue in the future, I found a solution that works for me:
mySelectQuery = "SELECT [DateTime] as StartDate, DATEADD(Day, [Time], [DateTime]) as EndDate, [Type] FROM [TaskTrack] WHERE [User] = '" + User.Identity.Name + "' AND DATEADD(Day, [Time], [DateTime]) >= getdate() ORDER BY [DateTime]";
string connStr = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;
SqlConnection conn = new SqlConnection(connStr);
DataSet ds = new DataSet();
dynamic adapter = new SqlDataAdapter(mySelectQuery, conn);
conn.Open();
adapter.Fill(ds);
Chart1.DataSource = ds;
Chart1.Series["Series1"].ChartType = System.Web.UI.DataVisualization.Charting.SeriesChartType.RangeBar;
Chart1.Series["Series1"].Label = "";
Chart1.Series["Series1"].XValueMember = "Type";
Chart1.Series["Series1"].YValueMembers = "StartDate,EndDate";
Chart1.Series["Series1"].ToolTip = "#VALY : #VALX";
Chart1.Series["Series1"].SmartLabelStyle.Enabled = true;
Chart1.ChartAreas["ChartArea1"].AxisX.LabelStyle.Enabled = false;
Chart1.ChartAreas["ChartArea1"].AxisX.MajorGrid.Enabled = false;
Chart1.ChartAreas["ChartArea1"].AxisY.MajorGrid.Enabled = false;
VerticalLineAnnotation VA;
ChartArea CA;
CA = Chart1.ChartAreas[0];
VA = new VerticalLineAnnotation();
VA.AxisX = CA.AxisX;
VA.AxisY = CA.AxisY;
VA.IsInfinitive = true;
VA.ClipToChartArea = CA.Name;
VA.Name = "myLine";
VA.ToolTip = DateTime.Now.ToString("dd-MM-yyyy");
VA.Height = CA.AxisY.Maximum - CA.AxisY.Maximum;
VA.IsInfinitive = true;
VA.ClipToChartArea = CA.Name;
VA.LineColor = Color.Red;
VA.LineWidth = 2; // use your numbers!
VA.X = DateTime.ParseExact(DateTime.Now.ToString("dd-MM-yyyy"), "dd-MM-yyyy", null).ToOADate();
Chart1.Annotations.Add(VA);
Chart1.DataBind();
conn.Close();
Dim LoginUser As MembershipUser = Membership.GetUser(HttpContext.Current.User.Identity.Name)
Dim sFormat As String = "00.00"
'Dim LoginUser = "P002"
Dim sqlapt As SqlDataAdapter = New SqlDataAdapter("select * from wpchannel", connection)
Dim sqlds As DataSet = New DataSet()
Dim sqldt As DataTable = New DataTable()
sqlapt.Fill(sqlds, "wpaccess")
sqldt = sqlds.Tables(0)
'Dim sum As Double
Dim row As DataRow
For Each row In sqldt.Rows
Dim strDetail As String
strDetail = row("username")
lbluserchk.Text = strDetail
If lbluserchk.Text = LoginUser.ToString Then
Dim sqlapt1 As SqlDataAdapter = New SqlDataAdapter("select * from wpchannel where username='" + LoginUser.ToString + "'", connection)
Dim sqlds1 As DataSet = New DataSet()
Dim sqldt1 As DataTable = New DataTable()
sqlapt1.Fill(sqlds1, "wpchannel")
sqldt1 = sqlds1.Tables(0)
Dim username As String = sqldt1.Rows(0).Item(1).ToString
Dim productid As String = sqldt1.Rows(0).Item(2).ToString
lblcheck1.Text = username.ToString
lblcheck2.Text = productid
'New check
Dim da As SqlDataAdapter
Dim ds As DataSet = New DataSet()
Dim dt As DataTable = New DataTable()
Dim sqlquery2 = "select convert(varchar(10), convert(datetime, dn.curdatetime),20) as DnDate ,DN.telcoid As TelecoId,round(convert(decimal(18,2),DN.USD),2) as USD,DN.DNStatus As DnStatus,count(*) as Total,sum(round(convert(decimal(18,2),DN.USD),2)) as subtotal from DN left join MO on DN.moid = mo.linkid where mo.channeltype in (select channelid from wpchannel where username='" + LoginUser.ToString + "') Group by convert(varchar(10), convert(datetime, dn.curdatetime),20),DN.telcoid,DN.USD,DN.DNStatus order by DnDate,dn.telcoid,dnstatus,USD"
da = New SqlDataAdapter(sqlquery2, connection)
da.Fill(ds, "MO")
dt = ds.Tables(0)
ViewState("dtpayment") = dt
Session("dtpayment") = dt
GridView1.DataSource = dt
GridView1.DataBind()
GridView1.FooterRow.Cells(2).Font.Bold = True
GridView1.FooterRow.Cells(2).ForeColor = Color.Black
GridView1.FooterRow.Cells(2).Text = " Grand Total:"
GridView1.FooterRow.Cells(2).HorizontalAlign = HorizontalAlign.Right
Dim sum As Double = Convert.ToDouble(dt.Compute("SUM(" + (dt.Columns(5).ColumnName) + ")", String.Empty))
Dim footernum As Double = sum.ToString
GridView1.FooterRow.Cells(3).Text = footernum.ToString()
Dim sumnum As Double = sum.ToString
lblsum.Text = sumnum.ToString()
ViewState("dt") = dt
ViewState("sort") = "Asc"
VerifyRenderingInServerForm(GridView1)
Exit For
Else
Dim cmd As SqlCommand
Dim da1 As SqlDataAdapter
Dim ds1 As DataSet = New DataSet()
Dim dt1 As DataTable = New DataTable()
'Dim sqlquery1 = "select convert(varchar(10), convert(datetime, dn.curdatetime),20) as DnDate ,DN.telcoid As TelecoId,round(convert(decimal(18,2),DN.USD),2) as USD,DN.DNStatus As DnStatus,count(*) as Total from DN left join MO on DN.moid = mo.linkid Group by convert(varchar(10), convert(datetime, dn.curdatetime),20),DN.telcoid,DN.USD,DN.DNStatus order by DnDate DESC,dn.telcoid,dnstatus,USD"
cmd = New SqlCommand
cmd.Connection = connection
cmd.CommandText = "logReport"
cmd.CommandType = CommandType.StoredProcedure
da1 = New SqlDataAdapter(cmd)
da1.Fill(ds1, "MO")
dt1 = ds1.Tables(0)
ViewState("dtpayment") = dt1
Session("dtpayment") = dt1
GridView1.DataSource = dt1
GridView1.DataBind()
GridView1.FooterRow.Cells(2).Font.Bold = True
GridView1.FooterRow.Cells(2).ForeColor = Color.Black
GridView1.FooterRow.Cells(2).Text = " Grand Total:"
GridView1.FooterRow.Cells(2).HorizontalAlign = HorizontalAlign.Right
Dim sum As Double = Convert.ToDouble(dt1.Compute("SUM(" + dt1.Columns(2).ColumnName + ")", String.Empty)) * Convert.ToDouble(dt1.Compute("SUM(" + dt1.Columns(4).ColumnName + ")", String.Empty))
Dim footernum As Double = sum
GridView1.FooterRow.Cells(3).Text = footernum.ToString()
Dim sumnum As Double = sum.ToString
lblsum.Text = sumnum.ToString()
ViewState("dt") = dt1
ViewState("sort") = "Asc"
VerifyRenderingInServerForm(GridView1)
Continue For
End If
'Exit Sub
Next row
Catch ex As Exception
Label1.Text = ex.ToString
'jscript = ("<script language=""JavaScript"">alert(""Error! Cannot conect to the database."");</script>")
'RegisterClientScriptBlock(x, jscript)
End Try
The read record is solved. I still have another problem the error message still remain there after user key in correct order id.
query = "select FoodName, Qty, IngredientName, Quantity, OrderStatus
from tblorder, tblorderdetail, tblfood, tblcustomizefooddetail, tblcustomizeingredient, tblordercustomize
where tblOrder.OrderId = #OrderId and OrderStatus = #OrderStatus and tblorder.OrderId = tblorderdetail.OrderId and tblorderdetail.FoodId = tblfood.FoodId and tblorderdetail.OrderDetailId = tblordercustomize.OrderDetailId and tblfood.FoodId = tblcustomizefooddetail.FoodId and tblcustomizeingredient.IngredientId = tblcustomizefooddetail.IngredientId and tblordercustomize.IngredientId = tblcustomizeingredient.IngredientId"
com = New MySqlCommand(query, conn)
com.Parameters.AddWithValue("#OrderId", txtOrderId.Text)
com.Parameters.AddWithValue("#OrderStatus", "Pending")
Dim sqladapter As New MySqlDataAdapter(com)
sqladapter.Fill(dt)
If dt.Rows.Count Then
GridView1.DataSource = dt
GridView1.DataBind()
Else
Label1.Text = "Order ID Doesn't Exist"
End If
Lets take your sample and modify it:
query = "select FoodName, Qty, IngredientName, Quantity, OrderStatus
from tblorder, tblorderdetail, tblfood, tblcustomizefooddetail, tblcustomizeingredient, tblordercustomize
where tblOrder.OrderId = #OrderId and OrderStatus = #OrderStatus and tblorder.OrderId = tblorderdetail.OrderId and tblorderdetail.FoodId = tblfood.FoodId and tblorderdetail.OrderDetailId = tblordercustomize.OrderDetailId and tblfood.FoodId = tblcustomizefooddetail.FoodId and tblcustomizeingredient.IngredientId = tblcustomizefooddetail.IngredientId and tblordercustomize.IngredientId = tblcustomizeingredient.IngredientId"
com = New MySqlCommand(query, conn)
com.Parameters.AddWithValue("#OrderId", txtOrderId.Text)
com.Parameters.AddWithValue("#OrderStatus", "Pending")
Dim adapter as new SqlDataAdapter(com)
adapter.Fill(dt)
if adapter.Tables(0).Rows.Count > 0
GridView1.DataSource = adapter.Tables(0)
GridView1.DataBind()
Else
Label1.Text = "Order ID Doesn't Exist"
End If
I am using this code to update database with new values. But it return message The thread was interrupted. What does it mean? What is wrong with my code?
Dim connStr As String = System.Configuration.ConfigurationManager.ConnectionStrings("DeskriptivaConnectionString").ConnectionString.ToString()
Dim txtName As Object = DirectCast(FormView1.FindControl("txtName"), TextBox)
Dim txtLastName As Object = DirectCast(FormView1.FindControl("txtLastName"), TextBox)
Dim txtInfo As Object = DirectCast(FormView1.FindControl("txtInfo"), TextBox)
Dim txtCity As Object = DirectCast(FormView1.FindControl("txtCity"), TextBox)
Dim txtPrize As TextBox = DirectCast(FormView1.FindControl("txtPrize"), TextBox)
Dim txtPhone As TextBox = DirectCast(FormView1.FindControl("txtPhone"), TextBox)
Dim txtMail As TextBox = DirectCast(FormView1.FindControl("txtMail"), TextBox)
Try
Using conn As New SqlConnection(connStr)
Dim cmd As SqlCommand = conn.CreateCommand()
cmd.CommandText = "UPDATE Profiles SET #Name = Name, #LastName = LastName, #Info = Info, #City = City, #Prize = Prize, #Phone = Phone, #Mail = Mail WHERE (UserName = #UserName)"
cmd.Parameters.Add("#Name", System.Data.SqlDbType.NVarChar).Value = txtName.Text
cmd.Parameters.Add("#LastName", System.Data.SqlDbType.NVarChar).Value = txtLastName.Text
cmd.Parameters.Add("#Info", System.Data.SqlDbType.NText).Value = MakeLink(HtmlRemoval.StripTagsCharArray(txtInfo.Text))
cmd.Parameters.Add("#City", System.Data.SqlDbType.NVarChar).Value = txtCity.Text
cmd.Parameters.Add("#Prize", System.Data.SqlDbType.NVarChar).Value = txtPrize.Text
cmd.Parameters.Add("#Phone", System.Data.SqlDbType.NVarChar).Value = txtPhone.Text
cmd.Parameters.Add("#Mail", System.Data.SqlDbType.NVarChar).Value = txtMail.Text
cmd.Parameters.Add("#UserName", System.Data.SqlDbType.NVarChar).Value = Context.User.Identity.Name
conn.Open()
cmd.ExecuteNonQuery()
conn.Close()
Response.Redirect(ResolveClientUrl("~/Profil/"))
End Using
Catch ex As Exception
MsgBox(ex.Message)
End Try
Use Response.Redirect(ResolveClientUrl("~/Profil/"), false) with Context.ApplicationInstance.CompleteRequest(); instead of Response.Redirect(ResolveClientUrl("~/Profil/"))
check Correct use of System.Web.HttpResponse.Redirect blog post for more information
and also your sql parameters # symbol is in wrong place. change as below
UPDATE Profiles SET
Name = #Name, LastName
= #LastName, Info =
#Info, City = #City,
Prize = #Prize, Phone
= #Phone, Mail = #Mail
WHERE (UserName =
#UserName)
Updated Code
VB CODEBEHIND
Protected Sub cmdclick_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdclick.Click
Dim strConnString As String = WebConfigurationManager.ConnectionStrings("orca").ConnectionString
Dim con As New SqlConnection(strConnString)
Dim cmd As New SqlCommand("usp_validatecard", con)
cmd.CommandType = Data.CommandType.StoredProcedure
Dim GetTrack1 As String = ""
Dim GetTrack2 As String = ""
Dim SplitTrack As String = txtTrack.Text
If SplitTrack.Length.ToString = 19 Then
GetTrack1 = Mid(SplitTrack, 2, 6)
GetTrack2 = Mid(SplitTrack, 10, 9)
cmd.Parameters.Add("#track1", Data.SqlDbType.NVarChar).Value = GetTrack1
cmd.Parameters.Add("#track2", Data.SqlDbType.NVarChar).Value = GetTrack2
Try
con.Open()
Dim Result As Integer = cmd.ExecuteNonQuery()
Dim reader As SqlDataReader = cmd.ExecuteReader()
If reader.Read() Then
lblmemname.Text = Convert.ToString(reader(0))
lblmemnum.Text = Convert.ToString(reader(1))
lbltrack1.Text = Convert.ToString(reader(2))
lbltrack2.Text = Convert.ToString(reader(3))
lblmessage.Text = Convert.ToString(reader(4))
End If
Catch ex As SqlException
errmessage.Text = "Error"
Finally
con.Close()
End Try
ElseIf SplitTrack.Length.ToString = 8 Then
GetTrack1 = Mid(SplitTrack, 2, 6)
cmd.Parameters.Add("#track1", Data.SqlDbType.NVarChar).Value = GetTrack1
Try
con.Open()
Dim Result As Integer = cmd.ExecuteNonQuery()
Dim reader As SqlDataReader = cmd.ExecuteReader()
If reader.Read() Then
lblmemname.Text = Convert.ToString(reader(0))
lblmemnum.Text = Convert.ToString(reader(1))
lbltrack1.Text = Convert.ToString(reader(2))
lbltrack2.Text = Convert.ToString(reader(3))
lblmessage.Text = Convert.ToString(reader(4))
End If
Catch ex As SqlException
errmessage.Text = "Error"
Finally
con.Close()
End Try
ElseIf SplitTrack.Length.ToString = 11 Then
GetTrack2 = Mid(SplitTrack, 2, 9)
cmd.Parameters.Add("#track2", Data.SqlDbType.NVarChar).Value = GetTrack2
Try
con.Open()
Dim Result As Integer = cmd.ExecuteNonQuery()
Dim reader As SqlDataReader = cmd.ExecuteReader()
If reader.Read() Then
lblmemname.Text = Convert.ToString(reader(0))
lblmemnum.Text = Convert.ToString(reader(1))
lbltrack1.Text = Convert.ToString(reader(2))
lbltrack2.Text = Convert.ToString(reader(3))
lblmessage.Text = Convert.ToString(reader(4))
End If
Catch ex As SqlException
errmessage.Text = "Error"
Finally
con.Close()
End Try
Else
lblmessage.Text = "Could Not Find Any Tracks"
End If
MSSQL STORED PROCEDURE
ALTER Procedure [dbo].[usp_validatecard](
#memnum nvarchar(50) = '-',
#memname nvarchar(50) = '-',
#track1 nvarchar(50) = '-',
#track2 nvarchar(50) = '-',
#msgtrack1 nvarchar(50) = 'Track 1 is Blank',
#msgtrack2 nvarchar(50) = 'Track 2 is Blank',
#message nvarchar(100)= '-')
As
--select #cardid = '%128255? ;282556587?'
--select #track1 = '128255'
--select #track2 = '282556587'
-- track1 good, track2 good
If exists(select * from dbo.clubmembers where FAMILYID = #track1 and (CLUBCARD1 = #track2 or CLUBCARD2 = #track2))
begin
select #memname = lastname + ', ' + firstname, #memnum = MEMBERSHIPID from dbo.clubmembers where FAMILYID = #track1 and (CLUBCARD1 = #track2 or CLUBCARD2 = #track2)
if exists(select * from dbo.clubmembers where membershipid = #memnum and status = 'ACTIVE')
select #msgtrack1 = 'Track 1 is GOOD', #msgtrack2 = 'Track 2 is GOOD', #message = 'Card is GOOD'
else
select #msgtrack1 = 'Track 1 is GOOD but In-active', #msgtrack2 = 'Track 2 is GOOD but In-active', #message = 'Check Member Status in Membership'
end
-- track1 good and track2 bad
Else
If exists(select * from dbo.clubmembers where FAMILYID = #track1 and (CLUBCARD1 != #track2 and CLUBCARD2 != #track2))
begin
select #memname = lastname, #memnum = FAMILYID from dbo.clubmembers where FAMILYID = #track1 and (CLUBCARD1 != #track2 and CLUBCARD2 != #track2)
if exists(select * from dbo.clubmembers where FAMILYID = #track1 and (CLUBCARD1 != #track2 and CLUBCARD2 != #track2) and status = 'ACTIVE')
select #msgtrack1 = 'Track 1 is GOOD', #msgtrack2 = 'Track 2 is BAD', #message = 'Please re-encode card'
else
select #msgtrack1 = 'Track 1 is GOOD but In-Active', #msgtrack2 = 'Track 2 is BAD', #message = 'Please re-encode card and Check Member Status in Membership'
end
else
-- track1 bad, track2 good
If exists(select * from dbo.clubmembers where (CLUBCARD1 = #track2 or CLUBCARD2 = #track2) and FAMILYID != #track1)
begin
select #memname = lastname + ', ' + firstname, #memnum = MEMBERSHIPID from dbo.clubmembers where (CLUBCARD1 = #track2 or CLUBCARD2 = #track2)
If exists(select * from dbo.clubmembers where (CLUBCARD1 = #track2 or CLUBCARD2 = #track2) and FAMILYID != #track1 and STATUS = 'ACTIVE')
select #msgtrack1 = 'Track 1 is BAD', #msgtrack2 = 'Track 2 is GOOD', #message = 'Please re-encode card'
else
select #msgtrack1 = 'Track 1 is BAD', #msgtrack2 = 'Track 2 is GOOD but In-active', #message = 'Please re-encode card and Check member status in Membership'
end
select #memname, #memnum, #msgtrack1, #msgtrack2, #message
If you check if sp has two elements or not by doing
If sp.Length = 2 Then
...
End If
and inside the If block, you can do
Dim track1 as String = sp(0)
Dim track2 as String = sp(1)
C# is more to my liking but this is a rough cut of a method that will split your string, test for correct number of elements and then create database connection (assumed sql server but any ole db should work) and call your stored procedure.
Public Sub ProcessSwipe(ByVal value As String)
Dim splitValues() As String
Dim separator As Char = ";"
Dim connectionString As String = String.Empty
Dim storedProcName As String = String.Empty
' Edit these to sane values
connectionString = "Provider=SQLOLEDB;BData Source=localhost;Initial Catalog=msdb;Integrated Security=SSPI;"
storedProcName = "dbo.SaveSwipe"
If String.IsNullOrEmpty(value) Then
MsgBox("No value provided from swipe")
Return
End If
Try
splitValues = value.Split(separator)
If splitValues.Length <> 2 Then
MsgBox(String.Format("Splitting of swipe data did not result in 2 values. Swiped value is {0}", value))
Return
End If
' At this point, we should have an array with 2 elements in it
' Open a connection
Using connection As New OleDb.OleDbConnection(connectionString)
connection.Open()
Using Command As New OleDb.OleDbCommand
Command.CommandText = storedProcName
Command.CommandType = CommandType.StoredProcedure
Command.Connection = connection
' Assumes your proc takes 2 parameters, named swipe1 and swipe2
' Update to sane values
Command.Parameters.AddWithValue("#swipe1", splitValues(0))
Command.Parameters.AddWithValue("#swipe2", splitValues(1))
' Make the actual call to your stored procedure
Command.ExecuteNonQuery()
End Using
End Using
Catch ex As Exception
MsgBox(String.Format("Attempt to split {0} failed. {1}", value, ex))
End Try
End Sub
Sub Main()
Dim shorty As String
Dim works As String
Dim longun As String
Dim nuthin As String
shorty = "%128565?"
works = "%128565?;229584115?"
longun = "%128565?;229584115?%128565?;229584115?"
nuthin = Nothing
ProcessSwipe(shorty)
ProcessSwipe(works)
ProcessSwipe(longun)
ProcessSwipe(nuthin)
End Sub