开发者

SQL Statement help in vb.net

Sub Bind_dgList()
Dim strCommand As String     
Dim strConnect As String     
Dim DBDataAdapter_Leads As OleDbDataAdapter     
Dim DBConnection_List As OleDbConnection     
Dim DBDataSet_Leads As DataSet
Dim DBDataView_Leads As DataView

strConnect = GetDBConnectionString()     
DBConnection_List = New OleDbConnection(strConnect)     
strCommand = "SELECT * Manager FROM tblList ORDER BY Names"     
DBDataAdapter_Leads = New OleDbDataAdapter(strCommand, DBConnection_List)    开发者_如何学编程 DBDataSet_Leads = New DataSet     
DBDataAdapter_Leads.Fill(DBDataSet_Leads, "tblList")     
DBDataView_Leads = New DataView(DBDataSet_Leads.Tables("tblList"))      
dgList.DataSource = DBDataView_Leads     
dgList.DataBind() 

End Sub 

Can anyone help me with the above code? I want to select distinct record of names. Some of the names are repeating. May I know how to do it?

I have used all the above. But There is an error showing.

First error : Server Error in '/wwwroot' Application. Syntax error (missing operator) in query expression '* Manager'. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.OleDb.OleDbException: Syntax error (missing operator) in query expression '* Manager'.

Source Error: Line 71: DBDataAdapter_FocalLeads = New OleDbDataAdapter(strCommand, DBConnection_AgentList) Line 72: DBDataSet_FocalLeads = New DataSet Line 73: DBDataAdapter_FocalLeads.Fill(DBDataSet_FocalLeads, "tblAgentList") Line 74: DBDataView_FocalLeads = New DataView(DBDataSet_FocalLeads.Tables("tblAgentList"))

Line 75: Second Error : DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'FieldId'. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Web.HttpException: DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'FieldId'.

Source Error: Line 75: Line 76: dgAgentList.DataSource = DBDataView_FocalLeads Line 77: dgAgentList.DataBind() Line 78: End Sub

Line 79: But When am using this there is no error, but the manager names are repeating. strCommand = "SELECT * FROM tblAgentList ORDER BY Manager"

Am doing this to mass edit and update the records. If I can get help in doing the mass updating I can ignore this page. Now I have to edit line by line. So if there is change in a managers role and its repeating 5 times. I need to manually edit one by to update. So is there a way to do a mass update?

Thank you for the help.. I really appreciate.. :)


I have used all the above. But There is an error showing.

First error : Server Error in '/wwwroot' Application. Syntax error (missing operator) in query expression '* Manager'. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.OleDb.OleDbException: Syntax error (missing operator) in query expression '* Manager'.

Source Error: Line 71: DBDataAdapter_FocalLeads = New OleDbDataAdapter(strCommand, DBConnection_AgentList) Line 72: DBDataSet_FocalLeads = New DataSet Line 73: DBDataAdapter_FocalLeads.Fill(DBDataSet_FocalLeads, "tblAgentList") Line 74: DBDataView_FocalLeads = New DataView(DBDataSet_FocalLeads.Tables("tblAgentList"))

Line 75:

Second Error : DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'FieldId'. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Web.HttpException: DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'FieldId'.

Source Error: Line 75: Line 76: dgAgentList.DataSource = DBDataView_FocalLeads Line 77: dgAgentList.DataBind() Line 78: End Sub

Line 79:

But When am using this there is no error, but the manager names are repeating. strCommand = "SELECT * FROM tblAgentList ORDER BY Manager"

Am doing this to mass edit and update the records. If I can get help in doing the mass updating I can ignore this page. Now I have to edit line by line. So if there is change in a managers role and its repeating 5 times. I need to manually edit one by to update. So is there a way to do a mass update?

Thank you for the help.. I really appreciate.. :)


Did you mean:

SELECT * FROM Manager tblList ORDER BY Names

or

SELECT *, Manager FROM tblList ORDER BY Names

?


Modify your SQL statement like this

SELECT DISTINCT Names FROM Manager ORDER BY Names

I don't think

SELECT * FROM

will work.


Assuming the rest of the code works all you should need to do is change this line

strCommand = "SELECT * Manager FROM tblList ORDER BY Names"

to this

strCommand = "SELECT DISTINCT * Manager FROM tblList ORDER BY Names"

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜