|
Hi
I am very new to this, but I would like to know how to pass a value to AccessDataSource as a parameter in order to update a table.
I have a dropdownlist, and I am able to grab the selected item from the dropdownlist, but I am to get the value into the DataSource and to then update the table.
Can someone explain to me or show me how.
Thanks
|
|
|
|
|
you can use : (If you have set NONE to parameter field while configuring datasource)
Accessdatasource1.UpdateParameters.Add("@parametername","parametervalue");
parameter value can be any value you are retrieveing from dropdownlist or textboz or any variable.
there are other ways too, by sessions or querystring etc
Good luck!
regards,
Sana
$@N@
|
|
|
|
|
Hi
thanks for your reply, but I couldn't get it to work. Below is my code snippet:
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
ProviderName="<%$ ConnectionStrings:NorthwindConnectionString.ProviderName %>"
SelectCommand="SELECT [EmployeeID], [LastName] FROM [Employees]">
</asp:SqlDataSource>
<asp:DropDownList ID="DropDownList1" runat="server"
DataSourceID="SqlDataSource1" DataTextField="LastName"
DataValueField="EmployeeID" AutoPostBack="true">
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource3" runat="server"
ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
ProviderName="<%$ ConnectionStrings:NorthwindConnectionString.ProviderName %>"
UpdateCommand="UPDATE [Employees] SET [NotActive]=@NotActive WHERE [EmployeeID]=@EmployeeID">
<UpdateParameters>
<asp:Parameter Name="NotActive" DefaultValue="YES" Type="String" />
<asp:ControlParameter ControlID="DropDownList1" Name="EmployeeID" PropertyName="SelectedValue" />
</UpdateParameters>
</asp:SqlDataSource>
<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False"
DataSourceID="SqlDataSource3" Visible="true">
<Columns>
<asp:BoundField DataField="LastName" HeaderText="LastName"
SortExpression="LastName" />
<asp:BoundField DataField="Active" HeaderText="Active"
SortExpression="Active" />
<asp:BoundField DataField="NotActive" HeaderText="NotActive"
SortExpression="NotActive" />
</Columns>
</asp:GridView>
I have been experimenting by using a parameter tag in order to hold a default value which when the Update query is run the default is passed to the query. Unfortunately, when I check the table it hasn't updated.
What do I need to do fix the problem?
Thanks
|
|
|
|
|
ok fine.. well in my last reply there was a mistake there should be no "@" with parameter name.
well u do...
on the UPDATE button or DropDownList_SelectedValueChanged event place the following lines!
SqlDataSource3.UpdateParameters.Add("NotActive","Yes");
SqlDataSource3.UpdareParameters.Add("EmployeeID",DropDownList1.SelectedValue);
I am passing paramters to my datasource in the above way and its working.
Set the placement of these lines as per ur code.
Hope its work!
Good Luck
$@N@
|
|
|
|
|
Sorry, I don't what's a matter with me on something that should be a breeze in the park, but I can't this work. I am not getting any error message, but no value is being passed.
So, I started again and tried to keep it simple. I have one dropdownlist and one button. Below is the markup followed by the VB Code behind:
<asp:DropDownList ID="DropDownList1" runat="server"
DataSourceID="AccessDataSource1" DataTextField="LastName"
DataValueField="LastName">
</asp:DropDownList>
<asp:AccessDataSource ID="AccessDataSource1" runat="server"
DataFile="~/Northwind.mdb" SelectCommand="SELECT [LastName] FROM [Employees]">
</asp:AccessDataSource>
<asp:AccessDataSource ID="AccessDataSource2" runat="server"
DataFile="~/Northwind.mdb"
UpdateCommand="UPDATE [Employees] SET [NotActive] = ? WHERE [EmployeeID] = @[EmployeeID]">
</asp:AccessDataSource>
<asp:Button ID="Button1" runat="server" Text="Click Me" />
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
AccessDataSource2.UpdateParameters.Add("NotActive", "YES")
AccessDataSource2.UpdateParameters.Add("EmployeeID", DropDownList1.SelectedValue)
End Sub
Can you please look through, correct and point out to me where I am going wrong!
Thanks
|
|
|
|
|
hmmm once i have faced the similar situation while updating records; that there was no error or exception but database is not updated..
try the following inside the button click event:
if(!page.IsPostBack)
{
AccessSource1.UpdateParamters.Add("NoActive","yes");
AccessSource1.UpdateParamters.Add("EmployeeID",DropDownList1.SelectedValue);
}
$@N@
|
|
|
|
|
Hi
I am trying to add a childnode to a treeview in visual basic, but I am able to do so. Can someone give me an example how to do this, please? Below is my method in which I add my parent nodes:
Private Sub PopulateNodes(ByVal dt As DataTable, ByVal nodes As TreeNodeCollection)
Dim var As String
For Each r As DataRow In dt.Rows
Dim tn As New TreeNode()
If r("Active").ToString = "YES" Then
tn.Text = r("LastName").ToString()
tn.Value = r("EmployeeID").ToString()
tn.ImageUrl = ("~/word.png")
ElseIf r("Active").ToString Is Nothing Then
THIS IS WHERE I NEED TO ADD A CHILD NODE
Else
tn.Text = r("LastName").ToString()
tn.Value = r("EmployeeID").ToString()
tn.ImageUrl = ("~/has_store_basic.png")
var = Server.UrlEncode(r("LastName").ToString())
tn.NavigateUrl = ("Results.aspx?Value=" & var)
End If
nodes.Add(tn)
End Sub
|
|
|
|
|
Any Help will do!!!
I am using this code to display an image from a sql server to an asp.net page:
dr.Read();
{
Response.ContentType = "image/Jpeg";
Response.Expires = 0;
Response.Buffer = true;
Response.Clear();
Response.BinaryWrite((byte[])dr["FileData"]);
Response.End();
}
And all I see is this on the page : System.Web.HttpPostedFile
Please help me!!!
|
|
|
|
|
This might be a completely stupid question, but do you actually have an image in the database, or just a series of bytes that translates to the string "System.Web.HttpPostedFile"
|
|
|
|
|
Or is it possible that the image may have not been saved in the database correctly?
Be careful, there is no Undo Button(Ctrl+Z) in life.
|
|
|
|
|
crudeCodeYogi wrote: Or is it possible that the image may have not been saved in the database correctly?
That's what I was implying.
|
|
|
|
|
well in the 2005 sql db the field type is image and when I open the table I field reads BinaryData, does that mean the image is corrupted.
|
|
|
|
|
Anita_Kamat_inds wrote: well in the 2005 sql db the field type is image
image is deprecated, use varbinary(max) instead.
Anita_Kamat_inds wrote: when I open the table I field reads BinaryData, does that mean the image is corrupted
No, I'm suggesting you never put the image in there correctly in the first place.
|
|
|
|
|
OK, Will try changing the field type, and see what happens. Thanks Man.
|
|
|
|
|
Going by what you get back in your application, I suspect it was the input of data from your .NET application that was in error.
|
|
|
|
|
this is the code I am using to insert the image into the db. I think this line of code has en error:
nBytesRead = theStream.Read(Buffer, 0, BUFFER_SIZE);
the BUFFER_SIZE should be the size of the image,not a const. my guess.
const int BUFFER_SIZE = 255;
int nBytesRead = 0;
Byte[] Buffer = new Byte[BUFFER_SIZE];
StringBuilder strUploadedContent = new StringBuilder("");
Stream theStream = uplTheFile.PostedFile.InputStream;
nBytesRead = theStream.Read(Buffer, 0, BUFFER_SIZE);
while (0 != nBytesRead)
{
strUploadedContent.Append(Encoding.ASCII.GetString(Buffer, 0, nBytesRead));
nBytesRead = theStream.Read(Buffer, 0, BUFFER_SIZE);
}
HttpPostedFile UploadPic = uplTheFile.PostedFile;
int UploadPicLength = UploadPic.ContentLength;
byte[] PicArray = new byte[UploadPicLength];
UploadPic.InputStream.Read(PicArray, 0, UploadPicLength);
OleDbConnection conn = new OleDbConnection(System.Configuration.ConfigurationManager.ConnectionStrings["XXXXXX"].ConnectionString);
OleDbCommand cmd = new OleDbCommand();
cmd.Connection = conn;
string strSQL = "Update tbl set FileData= '" + UploadPic + "' WHERE (ID = 'xcv') ";
|
|
|
|
|
I have an actual image saved in the DB
|
|
|
|
|
do you think that msg means that the image is corrupted.
|
|
|
|
|
I have a employee class and manager class derived from it . I want to show the objects/records of both the base
class (employee class) and derived class (manager class) in a single gridview . How can i bind both the base
class n derived class in a gridview ? pls send me a link or code . In addition to this , i want to show the
records of base class and dervied class with different colours on grid ? how can i do that ? pls help , its
urgent !
|
|
|
|
|
dotnet.coder wrote: pls send me a link or code
www.rentacoder.com
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|
|
I would like to be able to select absolute positioning for 'Label' controls but whenever I select this control type the 'Position...' item in 'Format' is disabled. Why is it so? Is there a way to select absolute positioning for this type of control? Thanks!
----------------------------------------------------------
this is a sig++
|
|
|
|
|
Hi All,
I am trying to use a autocomplete Ajax tool for a textbox to register search possibilities from the database. For some reason when I load up the application nothing happens. My web method is below and Im not sure if there is anything wrong with it since it does return an array of strings from the datatable.
Would someone be able to assist with this? Many thanks and kind regards.
<br />
using System;<br />
using System.Collections;<br />
using System.Linq;<br />
using System.Web;<br />
using System.Web.Services;<br />
using System.Web.Services.Protocols;<br />
using System.Xml.Linq;<br />
using System.Collections.Generic;<br />
using System.Data;<br />
using System.Configuration;<br />
<br />
using System.Web.Security;<br />
using System.Web.UI;<br />
using System.Web.UI.HtmlControls;<br />
using System.Web.UI.WebControls;<br />
using System.Web.UI.WebControls.WebParts;<br />
<br />
using System.Data.SqlClient;<br />
<br />
[WebService(Namespace = "http://hello.org/")]<br />
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]<br />
[System.Web.Script.Services.ScriptService]<br />
public class WebService : System.Web.Services.WebService {<br />
<br />
public WebService () {<br />
<br />
}<br />
<br />
<br />
<br />
<br />
<br />
[WebMethod]<br />
public string[] GetCountry(string country)<br />
{<br />
<br />
string query = "SELECT COUNTRY FROM CUSTOMERS WHERE COUNTRY LIKE @Country";<br />
using (SqlConnection conn = new SqlConnection("Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\NORTHWND.MDF;Integrated Security=True;User Instance=True"))
{<br />
<br />
SqlDataAdapter adapter = new SqlDataAdapter(query, conn);<br />
adapter.SelectCommand.Parameters.Add("@Country", SqlDbType.VarChar,15).Value = country + "%";<br />
DataTable dt = new DataTable();<br />
adapter.Fill(dt);<br />
string[] items = new string[dt.Rows.Count];<br />
int i = 0;<br />
foreach (DataRow dr in dt.Rows)<br />
{<br />
items.SetValue(dr["Country"].ToString(), i);<br />
<br />
i++;<br />
}<br />
return items ;<br />
<br />
<br />
<br />
<br />
}<br />
}<br />
|
|
|
|
|
how to open a new window in asp.net using javascript? i should also be able to control its size parameters . and i want to place some controls like textbox in it..
|
|
|
|
|
its a basic question just read javascript window.open function...
umerumerumer
|
|
|
|
|
You can use window.open()[^] javascript method.
window.open ("http://www.codeproject.com","mywindow","location=1,status=1,scrollbars=1,width=100,height=100");
Be careful, there is no Undo Button(Ctrl+Z) in life.
|
|
|
|